int maina()
{
    LinkedList* l;

    l = LinkedList_new();

	LinkedListIterator* iter = LinkedList_getIterator(l);
	if (LinkedListIterator_hasMore(iter))
	{
		return 1;
	}
	if (LinkedListIterator_getNext(iter) != NULL)
	{
		return 2;
	}
	if (LinkedListIterator_getSame(iter) != NULL)
	{
		return 3;
	}
	LinkedListIterator_delete(iter);

	int i;
	int* j;
    // Add 100 integer pointers to list.
    for (i = 0; i < 100; i++)
    {
        j = malloc(sizeof(int));
        *j = i;
        LinkedList_addLast(l, j);
    }
	iter = LinkedList_getIterator(l);
	int count = 0;
	while (LinkedListIterator_hasMore(iter))
	{
		j = LinkedListIterator_getNext(iter);
		if (count != *j)
		{
			return 4;
		}
		count++;
		if (j != LinkedListIterator_getSame(iter))
		{
			return 5;
		}
	}
	if (count != 99)
	{
		return 6;
	}
	LinkedListIterator_delete(iter);
    LinkedList_deleteContents(l, intDeleter);
    LinkedList_delete(l);

    return 0;
}
Beispiel #2
0
void RenderBatch_delete(void* batch)
{
    smug_assert(NULL != batch);

    RenderBatch* thebatch = (RenderBatch*)batch;
    BatchData_delete(thebatch->data);

    freeBuffer(&thebatch->vertexBufferIndex);
    freeBuffer(&thebatch->colorBufferIndex);
    freeBuffer(&thebatch->textureBufferIndex);

    // Delete only list, don't touch drawables
    LinkedList_delete(thebatch->drawables);

    free(thebatch);
}
Beispiel #3
0
void PathName_delete(PathName* self)
{
    smug_assert(_invariant(self));
    if (self->root)
    {
        String_delete(self->root);
    }
    if (self->bareName)
    {
        String_delete(self->bareName);
        if (self->extension)
        {
            String_delete(self->extension);
        }
    }
    LinkedList_deleteContents(self->path, String_deleteVoid);
    LinkedList_delete(self->path);
    free(self);
}
/* --------- */
int
Luna_run(Luna *self)
{
	char *inputBuffer;
	int pid, sentBytes, errors;
	Transmitter *lcTransmitter;
	LinkedList *relayHosts;
	Receiver *lcReceiver;
	User *lcUser;

	if (!self) { return 0; }

	/* load user */
	if ((lcUser = User_new(self->_user)) == NULL) {
		printf("Unable to load user: %s\n%s\n", self->_user, LUNA_HAIKU_1);
		return 0;
	}

	if ((relayHosts = LinkedList_maskFromList(User_userData(lcUser), 5, LinkedList_count(User_userData(lcUser)) - 4)) == NULL) {
		printf("Unable to mask user %s's relay hosts; ensure relay hosts exist in %s's configuration.\n%s\n", 
				self->_user, self->_user, LUNA_HAIKU_3);
		User_delete(lcUser);
		return 0;
	}

	/* build transmission */
	if ((lcTransmitter = Transmitter_new(self, relayHosts, User_entropyList(lcUser))) == NULL) { 
		printf("Unable to create transmitter.\n%s\n", LUNA_HAIKU_3); 
		User_delete(lcUser);
		LinkedList_delete(relayHosts); 
		return 0; 
	}
	if (self->_verbose) { printf("Using max time lapse: %d.\n", self->_maxTimeLapse); }

	/* build receiver */
	if ((lcReceiver = Receiver_new(self)) == NULL) {
		printf("Unable to create receiver.\n%s\n", LUNA_HAIKU_3);
		User_delete(lcUser);
		LinkedList_delete(relayHosts); 
		Transmitter_delete(lcTransmitter);
		return 0;
	}
	if (!(pid = Receiver_listen(lcReceiver, __defaultListener))) {
		printf("Unable to listen on %s, transmitting only.\n", self->_device);
		exit(0);
	} else {
		if (self->_verbose) { printf("Listening for replies on %s\n", self->_device); }
	}

	/* initialize input */
	inputBuffer = (char *)malloc(self->_datagramSize);
	if (!inputBuffer) { 
		printf("Unable to alloc input buffer.\n%s\n", LUNA_HAIKU_3); 
		User_delete(lcUser);
		LinkedList_delete(relayHosts); 
		Transmitter_delete(lcTransmitter);
		Receiver_delete(lcReceiver);
		return 0; 
	}
	bzero(inputBuffer, self->_datagramSize);

	/* transfer data */
	errors = 0;
	printf("Please enter data on separate lines followed by a carriage return; EOF (Ctrl+D) to terminate Luna.\n");
	for (; fgets(inputBuffer, self->_datagramSize, stdin); ) {
		if ((sentBytes = (self->_maxTimeLapse)
			? Transmitter_relayInjectAtMaxTimeLapse(lcTransmitter, self->_destination, self->_maxTimeLapse, inputBuffer, __defaultEncodingHandler)
			: Transmitter_relayInject(lcTransmitter, self->_destination, inputBuffer, __defaultEncodingHandler))) {
		} else {
			/* failure */
			if (self->_maxErrors < ++errors) {
				printf("Quitting due to excessive errors.\n%s\n", LUNA_HAIKU_4);
				break;
			}
		}
	}

	/* vocalize */
	if (self->_verbose) {
		printf("Transmitted %u time(s) for a travelling total of %u bytes.\n",
			Transmitter_count(lcTransmitter), Transmitter_bytes(lcTransmitter));
	}

	/* cleanup */
	free(inputBuffer);
	User_delete(lcUser);
	LinkedList_delete(relayHosts);
	Receiver_delete(lcReceiver);
	Transmitter_delete(lcTransmitter);

	return 0;
}