Пример #1
0
Файл: battle.c Проект: phoboz/yz
static int move_battle_walk(
    BATTLE_ACTOR *ba
)
{
    STEP_POINT *p, *q;

    p = (STEP_POINT *) LIST_HEAD(&ba->walkList);
    if (p == NULL) {

        return 1;

    }

    q = (STEP_POINT *) LIST_NEXT(&p->listNode);
    if (q == NULL) {

        ba->i = p->i;
        ba->j = p->j;

#ifdef DEBUG
        printf("Last element [%d, %d]",
               p->i, p->j);
#endif

        listRemove(&ba->walkList, &p->listNode);
        free(p);

#ifdef DEBUG
        printf(", %d element(s) left\n",
               listCount(&ba->walkList));
#endif

        return 1;

    }

    if (move_player_to(ba->player,
                       q->i * BMARKER_WIDTH,
                       q->j * BMARKER_HEIGHT)) {

#ifdef DEBUG
        printf("[%d, %d] -> [%d, %d]",
               p->i, p->j,
               q->i, q->j);
#endif

        listRemove(&ba->walkList, &p->listNode);
        free(p);

#ifdef DEBUG
        printf(", %d element(s) left\n",
               listCount(&ba->walkList));
#endif

    }

    return 0;
}
Пример #2
0
//*****************************************************************************
// hooks
//*****************************************************************************
void furniture_append_hook(const char *info) {
  OBJ_DATA *obj = NULL;
  CHAR_DATA *ch = NULL;
  hookParseInfo(info, &obj, &ch);

  if(objIsType(obj, "furniture")) {
    int num_sitters = listSize(objGetUsers(obj));

    // print out how much room there is left on the furniture
    int seats_left = (furnitureGetCapacity(obj) - num_sitters);
    if(seats_left > 0)
      bprintf(charGetLookBuffer(ch), 
	      " It looks like it could fit %d more %s.\r\n",
	      seats_left, (seats_left == 1 ? "person" : "people"));

    // print character names
    if(num_sitters > 0) {
      LIST *can_see = find_all_chars(ch, objGetUsers(obj), "", NULL, TRUE);
      listRemove(can_see, ch);

      char *chars = print_list(can_see, charGetName, charGetMultiName);
      if(*chars) bprintf(charGetLookBuffer(ch), "%s %s %s %s%s.\r\n",
			 chars, (listSize(can_see) == 1 ? "is" : "are"),
			 (furnitureGetType(obj) == FURNITURE_AT ? "at":"on"),
			 see_obj_as(ch, obj),
			 (charGetFurniture(ch) == obj ? " with you" : ""));
      deleteList(can_see);
      free(chars);
    }
  }
}
Пример #3
0
Файл: bio.c Проект: phoboz/vmx
void brelse (
    struct buf * bp
    ) {
    LIST *pBufHead = &bp->b_vp->v_mount->mnt_buflist;

    if ((bp->b_flags & B_BUSY) == 0) {
#ifdef DIAGNOSTIC
        logMsg ("brelse: buffer is not busy",
                0, 0, 0, 0, 0, 0);
#endif
        return;
    }
    
    /* anyone need this very block? */
    if (bp->b_flags & B_WANTED) {
        bp->b_flags &= ~B_WANTED;
        semGive (&bp->b_sem);
    }

    /* Put buffer at head */
    listRemove (pBufHead, &bp->b_node);        /* Remove from list */
    listInsert (pBufHead, NULL, &bp->b_node);  /* Insert at list head */

    /* unlock */
    bp->b_flags &= ~(B_WANTED | B_BUSY | B_ASYNC);
}
Пример #4
0
Файл: bio.c Проект: phoboz/vmx
int buf_wait (
    struct buf * bp
    ) {
    LIST *pBufHead = &bp->b_vp->v_mount->mnt_buflist;

    /* Make sure I/O is complete */
    if ((bp->b_flags & B_DONE) == 0) {
        if (bio_wait (bp->b_bio)) {
            bp->b_flags |= B_ERROR;
        }
        buf_done (bp, OK);
    }

    if ((bp->b_flags & B_ERROR) || bp->b_error) {
        if ((bp->b_flags & B_INVAL) == 0) {
            bp->b_flags |= B_INVAL;
            listRemove (pBufHead, &bp->b_node);        /* Remove from list */
            listInsert (pBufHead, NULL, &bp->b_node);  /* Insert at list head */
        }
        if (!bp->b_error) {
            bp->b_error = EIO;
        } else {
            bp->b_flags |= B_ERROR;
        }
        return (bp->b_error);
    } else {
        return (OK);
    }
}
Пример #5
0
/* Essa funcao existe para simplificar a macro de stackPop e evitar maiores problemas. */
int stackPop_FUNC(list *stack) {
	list aux = *stack;
	int val = aux->val;
	*stack = aux->prev;
	listRemove(aux);
	return val;
}
Пример #6
0
/*
 * Freeing memory from the small heap
 */
void SH_free(void *mem) {
	//First check if memory was allocated using malloc()
	void * adr = listGetMallocedMemoryAdr(mallocList, mem);
	if (adr != NULL ) {
		free(adr); // Memory was allocated using malloc(), use free instead
		listRemove(mallocList, adr); // Remove address from the list
		return;
	}

	// Memory was not allocated by using malloc, find which small heap it was put into.
	//struct shMapType * shMapEntry = listGetMemoryLocation(SHList, pthread_self());
	// changed to extract allocator's thread_id from mem header rather than by using pthread_self()
	void *ptr = mem - sizeof(SHMemHeaderStruct);
	SHMemHeader header = (SHMemHeader) ptr;
	struct shMapType * shMapEntry = listGetMemoryLocation(SHList, header->thread_id);

	my_mutex_lock(&shMapEntry->mutex);
	unsigned int toFree;  // Pointer to block that needs to be freed
	unsigned int cur, prev;

	toFree = ((unsigned int *) ptr - (shMapEntry->memArea + 1));

	if (toFree < shMapEntry->available) {  // If block, that is being freed is before the first free block

		if (((refToNextBlock(toFree, shMapEntry->memArea) + 1) == shMapEntry->available) && shMapEntry->available < shMapEntry->memAreaSize) // If next free block is immediately after block that is being freed
			shMapEntry->memArea[toFree] += (shMapEntry->memArea[shMapEntry->available] + 1);  // Defragmentation of free space
		else
			shMapEntry->memArea[refToNextBlock(toFree, shMapEntry->memArea)] = shMapEntry->available;

		shMapEntry->available = toFree;
	}

	else {  // If block, that is being freed isn't before the first free block

		prev = cur = shMapEntry->available;

		while (cur < toFree) {
			prev = cur;
			cur = nextBlock(cur, shMapEntry->memArea);
		}

		if ((refToNextBlock(prev, shMapEntry->memArea) + 1) == toFree) { // If previous free block is immediately before block that is being freed

			shMapEntry->memArea[prev] += (shMapEntry->memArea[toFree] + 1);  // Defragmentation of free space

			if (((refToNextBlock(toFree, shMapEntry->memArea) + 1) == cur) && cur < shMapEntry->memAreaSize) // If next free block is immediately after block that is being freed
				shMapEntry->memArea[prev] += (shMapEntry->memArea[cur] + 1);  // Defragmentation of free space
			else
				shMapEntry->memArea[refToNextBlock(toFree, shMapEntry->memArea)] = cur;
		} else {
			shMapEntry->memArea[refToNextBlock(prev, shMapEntry->memArea)] = toFree;
			shMapEntry->memArea[refToNextBlock(toFree, shMapEntry->memArea)] = cur;
		}

	}
	// jonl changed following line as NULL is incorrect, however, it is unclear what it shouldbe
	//log_into_file("freed from", ptr, NULL );
	log_into_file("freed from", ptr, 0 );
	my_mutex_unlock(&shMapEntry->mutex);
}
Пример #7
0
void testRemoval() {
    LList *list = newList( comparisonFunction );
    const int numElements = 1000;

    // Insert elements
    for( int i = 0; i < numElements; i++ ) {
        listInsert( list, mallocInt(i) );
    }

    // Remove the elements and ensure that the right elements were removed
    for( int i = 0; i < numElements; i++ ) {
        int *elementToRemove = mallocInt(i);
        int *removedElement = listRemove( list, elementToRemove );

        assertNotNull( removedElement, "removedElement is null!\n" );

        int comparisonResult = list->comparisonFunction( elementToRemove, removedElement );
        assertTrue( comparisonResult == 0, "compare(%d, %d) != 0\n", *elementToRemove,
                *removedElement );

        free( elementToRemove );
        free( removedElement );
    }

    // Free the list
    listFree( list );
}
Пример #8
0
Файл: battle.c Проект: phoboz/yz
static int move_battle_strike(
    BATTLE *battle
)
{
    int result;
    int done = 0;
    BATTLE_ACTOR *ba = (BATTLE_ACTOR *) battle->currActor->arg;

    result = move_strike(battle->strike);
    if (result > 0) {

        ba->player->h->status.hp -= result;
        if (ba->player->h->status.hp <= 0) {

            ba->player->h->status.alive = 0;

#ifdef DEBUG
            printf("Character with index: %d perished.\n",
                   ba->index);
#endif

            listRemove(&battle->battleList, &ba->listNode);
            /* TODO: Free character */
        }
        done = 1;
    }

    return done;
}
Пример #9
0
void listDelete(list* thisList) {
    
    while(thisList->count)
        listRemove(thisList, 0);

    kfree(thisList);
}
Пример #10
0
static void writeAvailableImpl(connection_t connection) {
	connectionContext_t* pCContext  = connectionGetContext(connection);

	if (pCContext->status != status_waiting_write) {
		LOG(ERR, "Invalid state... ");
	}

    int err = completeWrite(pCContext);
    if (err < 0) {
    	externalServer_t* pServer  = pCContext->pExternalServer;
    	listRemove(pServer->activeConnections, pCContext);
		connectionContextDelete(pCContext, 1);
    }else {
    	if (err == 0) {
    		//write compelete
    		pCContext->status = status_active;
    		if (dataStreamGetSize(pCContext->readStream) > 0) {
    			readAvailableImpl(connection);
    		}else {
    			pCContext->status = status_waiting_read;
    			connectionWaitForRead(pCContext->connection, getGlobalEventBase());
    		}
    	}else {
    		pCContext->status = status_waiting_write;
    		connectionWaitForWrite(pCContext->connection, getGlobalEventBase());
    	}
    }
}
Пример #11
0
int listRemoveN(List root, int n)
{
    List element = listGet(root, n);
    if (element == NULL)
        return 0;               /* out-of-list exception */
    listRemove(root, element);
    return 1;
}
Пример #12
0
/* compare should return -1 on lesser, 0 on equal and 1 on greater */
int listRemoveVal(List root, void* val, int (*compare)(const void*, const void*))
{
    List element = listGetVal(root, val, compare);
    if (element == NULL || element->v == NULL)
        return 0;
    listRemove(root, element);
    return 1;
}
Пример #13
0
/*==============================================================================*/
felist *listFree(felist *node) {
  felist *t = NULL;

  if (node != NULL)
    t = node->next;
  listRemove(node);
  if (node != NULL) free(node);
  return t;
}
Пример #14
0
void update_persistent_room_from_game(const char *info) {
  ROOM_DATA *room = NULL;
  hookParseInfo(info, &room);
  listRemove(p_to_save, room);

  // have we been replaced by a non-persistent room?
  ROOM_DATA *new_room = worldGetRoom(gameworld, roomGetClass(room));
  if(roomIsPersistent(room) && new_room != NULL && !roomIsPersistent(new_room))
    worldClearPersistentRoom(gameworld, roomGetClass(room));
}
Пример #15
0
void listDelete(SList* list)
{
	if(list)
	{
		while(!listEmpty(list))
		{
			listRemove(list,0);
		}
		free(list);
	}
}
Пример #16
0
void test_listRemove_given_13_14_should_Remove_13_14_and_throw_exception(void)

{

 unsigned int err;



 { jmp_buf *PrevFrame, NewFrame; unsigned int MY_ID = (0); PrevFrame = CExceptionFrames[(0)].pFrame; CExceptionFrames[MY_ID].pFrame = (jmp_buf*)(&NewFrame); CExceptionFrames[MY_ID].Exception = (0x5A5A5A5A); if (_setjmp(NewFrame) == 0) { if (&PrevFrame)

 {

  listAdd(list , 13);

  listAdd(list , 14);



  UnityAssertEqualNumber((_U_SINT)((13)), (_U_SINT)((listRemove(list))), (((void *)0)), (_U_UINT)75, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((14)), (_U_SINT)((listRemove(list))), (((void *)0)), (_U_UINT)76, UNITY_DISPLAY_STYLE_INT);

  UnityFail( ("Should throw ERROR_LIST_EMPTY exception"), (_U_UINT)77);;

 }

 else { } CExceptionFrames[MY_ID].Exception = (0x5A5A5A5A); } else { err = CExceptionFrames[MY_ID].Exception; err=err; } CExceptionFrames[MY_ID].pFrame = PrevFrame; } if (CExceptionFrames[(0)].Exception != (0x5A5A5A5A))

 {

  UnityAssertEqualNumber((_U_SINT)((ERROR_LIST_EMPTY)), (_U_SINT)((err)), ("Expect ERROR_LIST_EMPTY exception"), (_U_UINT)81, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((0)), (_U_SINT)((list->size)), (((void *)0)), (_U_UINT)82, UNITY_DISPLAY_STYLE_INT);

 }



 ListDel(list);

}
Пример #17
0
void* listPopFront(List root)
{
    List last = listBegin(root);
    if (last)
    {
        void* tmp = last->v;
        listRemove(root, last);
        return tmp;
    }
    else
        return NULL;
}
Пример #18
0
END_TEST

START_TEST(test_strJoin)
{
    char **list;
    size_t size;

    listCreate(list, &size);
    listAdd(list, "foo", &size);
    listAdd(list, "bar", &size);
    listAdd(list, "xyz", &size);
    fail_unless(strEquals(strJoin(" ", list, size), "foo bar xyz"), NULL);
    fail_unless(strEquals(strJoin("()", list, size), "foo()bar()xyz"), NULL);
    listRemove(list, 1, &size);
    fail_unless(strEquals(strJoin(" ", list, size), "foo xyz"), NULL);
    listRemove(list, 1, &size);
    fail_unless(strEquals(strJoin(" ", list, size), "foo"), NULL);
    listRemove(list, 0, &size);
    fail_unless(strEquals(strJoin(" ", list, size), ""), NULL);
    listFree(list);
}
Пример #19
0
//
// tries to make a char parse var
PARSE_VAR *use_one_parse_token_char(CHAR_DATA *looker, PARSE_TOKEN *tok,
				    const char *name) {
  int    type = FOUND_NONE;
  void *found = find_specific(looker, name, "", "", FIND_TYPE_CHAR, tok->scope,
			      tok->all_ok, &type);

  // make sure we found something...
  if(found == NULL)
    return NULL;
  else {
    PARSE_VAR *var = newParseVar(PARSE_VAR_CHAR);

    // if multiple vals were possible, flag it
    var->multiple_possible = tok->all_ok;

    // make sure it's not us if that's not allowed
    if(type == FOUND_CHAR) {
      if(tok->self_ok || looker != found)
	var->ptr_val = found;
      else {
	deleteParseVar(var);
	var = NULL;
      }
    }
    // if we got a list, make sure we remove ourself as neccessary
    else if(type == FOUND_LIST) {
      if(!tok->self_ok)
	listRemove(found, looker);
      // make sure we're not empty...
      if(listSize(found) > 1) {
	var->ptr_val  = found;
	var->multiple = TRUE;
      }
      else if(listSize(found) == 1) {
	var->ptr_val = listPop(found);
	deleteList(found);
      }
      else {
	deleteList(found);
	deleteParseVar(var);
	var = NULL;
      }
    }
    // this shouldn't happen...
    else {
      deleteParseVar(var);
      var = NULL;
    }

    // return what we found, if anything
    return var;
  }
}
Пример #20
0
int evaluateLiberties(char *board, int x, int y, struct linked_list *waiting, struct linked_list *evaled, struct linked_list *nolibs, char col, int turn){
	BOOLEAN first = (waiting == NULL);
	if ((x > width) || (y > length) || (x <= 0) || (y <= 0)) {
		return UNDECIDED;
	} else if (board[toIndex(x,y)] == SPACE) {
		return TRUE;
	} else if (board[toIndex(x,y)] != col) {
		return FALSE;
	} else if (listMember(waiting, x, y) == TRUE) {
		return UNDECIDED;
	} else if (listMember(evaled, x, y) == TRUE) {
		return TRUE;
	} else if (listMember(nolibs, x, y) == TRUE) {
		return FALSE;
	} else {
		waiting = listAdd(waiting, x, y);
		if (evaluateLiberties(board, x+1, y, waiting, evaled, nolibs, col, turn) == TRUE
		    || evaluateLiberties(board, x, y+1, waiting, evaled, nolibs, col, turn) == TRUE
		    || evaluateLiberties(board, x, y-1, waiting, evaled, nolibs, col, turn) == TRUE
		    || evaluateLiberties(board, x-1, y, waiting, evaled, nolibs, col, turn) == TRUE) {
			listAdd(evaled, x, y);
			waiting = listRemove(waiting, x, y);
			return TRUE;
		} else {
			if (first == TRUE) {
				while ((*waiting).next != NULL) {
					listAdd(nolibs, (*(*waiting).next).x, (*(*waiting).next).y);
					(*waiting).next = listRemove((*waiting).next, (*(*waiting).next).x, (*(*waiting).next).y);
				}
				listAdd(nolibs, (*waiting).x, (*waiting).y);
				SafeFree(waiting);
				return FALSE;
			} else {
				return UNDECIDED;
			}
		}
	}
}
Пример #21
0
/*
 * Cancel the timer that was set for time <t> with callback <cb>.
 */
void disDropTime(Dispatcher *dis, double t, void (*cb)(Dispatcher *dis, double t, void *udata))
{
    DIS_Timer *timer;

    for (timer = listHead(&dis->timers); timer; timer = listNext(timer)) {
        if (timer->t == t && timer->cb == cb) {
            listRemove(&dis->timers, timer);
            free(timer);
            return;
        }
    }

    dbgAbort(stderr, "no such timer\n");
}
Пример #22
0
void test_listRemove_given_11_12_should_remove_11_and_remain_1_size(void)

{

 listAdd(list , 11);

 listAdd(list , 12);

 UnityAssertEqualNumber((_U_SINT)((11)), (_U_SINT)((listRemove(list))), (((void *)0)), (_U_UINT)61, UNITY_DISPLAY_STYLE_INT);

 UnityAssertEqualNumber((_U_SINT)((1)), (_U_SINT)((list->size)), (((void *)0)), (_U_UINT)62, UNITY_DISPLAY_STYLE_INT);

 ListDel(list);

}
void nfc_cb_data_deinit(nfc_jni_callback_data* pCallbackData)
{
   /* Destroy semaphore */
   if (sem_destroy(&pCallbackData->sem))
   {
      ALOGE("Failed to destroy semaphore (errno=0x%08x)", errno);
   }

   /* Remove from active semaphore list */
   if (!listRemove(&nfc_jni_get_monitor()->sem_list, pCallbackData))
   {
      ALOGE("Failed to remove semaphore from the list");
   }

}
/*******************************************************************************
**
** Function         phNxpNciHal_cleanup_cb_data
**
** Description      Clean up callback data
**
** Returns          None
**
*******************************************************************************/
void phNxpNciHal_cleanup_cb_data(phNxpNciHal_Sem_t* pCallbackData)
{
    /* Destroy semaphore */
    if (sem_destroy(&pCallbackData->sem))
    {
        NXPLOG_NCIHAL_E("phNxpNciHal_cleanup_cb_data: Failed to destroy semaphore (errno=0x%08x)", errno);
    }

    /* Remove from active semaphore list */
    if (listRemove(&phNxpNciHal_get_monitor()->sem_list, pCallbackData) != 1)
    {
        NXPLOG_NCIHAL_E("phNxpNciHal_cleanup_cb_data: Failed to remove semaphore from the list");
    }

    return;
}
Пример #25
0
Файл: battle.c Проект: phoboz/yz
static void free_battle_target(
    BATTLE_ACTOR *ba
)
{
    STEP_POINT *p;

    while ((p = (STEP_POINT *) LIST_HEAD(&ba->targetList)) != NULL) {
        listRemove(&ba->targetList, &p->listNode);
        free(p);
    }

#ifdef DEBUG
    printf("Free battle target, %d element(s) left\n",
           listCount(&ba->targetList));
#endif
}
Пример #26
0
// GLUT callback for mouse activity.
void mouse(int button, int state, int x, int y)
{
    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    {
        if (!(selected = listGetNearestNodegl(l, x, y)))
        {
            if (l)
                listAdd(l, (float)x, (float)y);
            else
                l = listNew((float)x, (float)y);
            
            count++;
            
            free(knot);
            
            if (uniform)
                knot = computeUniformKnot(order + 1, count - 1);
            else
                knot = computeNonUniformKnot(order + 1, count - 1);
        }
        
        glutPostRedisplay();
    }
    else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
    {
        if ((selected = listGetNearestNodegl(l, x, y)))
        {
            if (l == selected)
                l = listRemove(selected);
            else
                listRemoveAt(selected, 0);
            
            selected = 0;
            count --;
            
            free(knot);
            
            if (uniform)
                knot = computeUniformKnot(order + 1, count - 1);
            else
                knot = computeNonUniformKnot(order + 1, count - 1);
        }
        
        glutPostRedisplay();
    }
}
Пример #27
0
Event *event_construct2(Name name, const char *header, float branchLength, Event *parentEvent,
        Event *childEvent, EventTree *eventTree) {
    Event *event;
    event = event_construct(name, header, branchLength, parentEvent, eventTree);
#ifndef NDEBUG
    assert(parentEvent != NULL);
    assert(childEvent != NULL);
    assert(listContains(parentEvent->children, childEvent));
#endif
    listRemove(parentEvent->children, childEvent);
    listAppend(event->children, childEvent);
    childEvent->parent = event;
    childEvent->branchLength = childEvent->branchLength - event->branchLength;
    if (childEvent->branchLength < 0.0) {
        childEvent->branchLength = 0.0;
    }
    return event;
}
Пример #28
0
Файл: world.c Проект: phoboz/yz
void free_world(
  WORLD *world
  )
{
  FIELD *field;

  while ((field = (FIELD *) LIST_HEAD(&world->fieldList)) != NULL) {

    listRemove(&world->fieldList, (LIST_NODE *) field);
    free(field);

  }

  free(world->world_map);
  free_map(world->map);
  free_sprite(world->tiles);
  free(world);
}
Пример #29
0
int *retrieve(List *list , int *size)
{	
	int i = 0 ;
	int CountSize = 0;
	int *Storage;
	
	Storage = malloc(sizeof(int) * (*size));
	
	while(!listIsEmpty(list))
	{
		Storage[i++] = listRemove(list);
		CountSize++;
	}
	
	*size = CountSize;
	
	return Storage;
}
Пример #30
0
Файл: bio.c Проект: phoboz/vmx
struct buf* buf_getblk (
    struct vnode * vp,
    lblkno_t       blkno,
    unsigned       size
    ) {
    struct buf *bp;
    LIST *pBufHead = &vp->v_mount->mnt_buflist;

loop:
    if ((bp = buf_incore (vp, blkno)) != NULL) {
        if (bp->b_flags & B_BUSY) {
            bp->b_flags |= B_WANTED;
            semTake (&bp->b_sem, WAIT_FOREVER);
        }
        bp->b_flags |= (B_BUSY | B_CACHE);
        /*
         * check for size inconsistancies
         */
        if (bp->b_size != size) {
            logMsg ("getblk: invalid buffer size: %d\n",
                    (ARG) bp->b_size,
                    0, 0, 0, 0, 0);
            bp->b_flags |= B_INVAL;
            bwrite (bp);
            goto loop;
        }
    } else {
        if ((bp = buf_new (vp, blkno)) == NULL) {
            logMsg ("buf_getblk: no buffers",
                    0, 0, 0, 0, 0, 0);
            goto loop;
        }
        bp->b_dev = vp->v_mount->mnt_dev;
        bp->b_lblkno = blkno;
        bp->b_vp = vp;
        bio_new (bp);
        
        /* Put buffer at head */
        listRemove (pBufHead, &bp->b_node);
        listInsert (pBufHead, NULL, &bp->b_node);
    }

    return (bp);
}