Example #1
0
IO_METHOD(IoSeq, replaceFirstSeq)
{
	/*doc Sequence replaceFirstSeq(aSequence, anotherSequence, optionalStartIndex)
	Returns a new Sequence with the first occurance of aSequence
	replaced with anotherSequence in the receiver. If optionalStartIndex is
	provided, the search for aSequence begins at that index. Returns self.
	*/

	IoSeq *subSeq   = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 1);
	size_t startIndex = 0;

	if (IoMessage_argCount(m) > 2)
	{
		startIndex = IoMessage_locals_longArgAt_(m, locals, 2);
	}

	IO_ASSERT_NOT_SYMBOL(self);

	{
		UArray *a = DATA(self);
		UArray *b = DATA(subSeq);
		UArray *c = DATA(otherSeq);
		long i = UArray_find_from_(a, b, startIndex);
		if(i != -1)
		{
			UArray_removeRange(a, i, UArray_size(b));
			UArray_at_putAll_(a, i, c);
		}
	}
	return self;
}
Example #2
0
static enum mad_flow IoMP3Decoder_inputCallback(void *data, struct mad_stream *stream)
{
	IoMP3Decoder *self = data;
	struct mad_decoder *decoder = &(DATA(self)->decoder);
	
	IoMessage_locals_performOn_(DATA(self)->willProcessMessage, self, self);

	if (DATA(self)->isRunning)
	{
		UArray *ba = IoSeq_rawUArray(DATA(self)->inputBuffer);
		
		UArray_removeRange(ba, 0, DATA(self)->lastInputPos);
		
		{
			size_t size = UArray_size(ba);
			UArray_setSize_(ba, size + MAD_BUFFER_GUARD);
			memset(UArray_bytes(ba) + size, 0x0, MAD_BUFFER_GUARD);
			UArray_setSize_(ba, size);
		}
		
		if (UArray_size(ba) == 0) 
		{
			return MAD_FLOW_CONTINUE;
		}
		
		DATA(self)->lastInputPos = UArray_size(ba);
		
		mad_stream_buffer(stream, UArray_bytes(ba), UArray_size(ba));
	}
	
	return DATA(self)->isRunning ? MAD_FLOW_CONTINUE : MAD_FLOW_STOP;
}
Example #3
0
void UArray_clipBeforeLastPathComponent(UArray *self)
{
	long pos = UArray_findLastPathComponent(self);

	if (pos != -1)
	{
		UArray_removeRange(self, 0, pos);
	}
}
Example #4
0
BASEKIT_API int UArray_clipAfterStartOf_(UArray *self, const UArray *other)
{
    long index = UArray_find_(self, other);

    if (index > -1)
    {
        UArray_removeRange(self, index, self->size);
        return 1;
    }

    return 0;
}
Example #5
0
BASEKIT_API int UArray_clipBefore_(UArray *self, const UArray *other)
{
    long index = UArray_find_(self, other);

    if (index > -1)
    {
        UArray_removeRange(self, 0, index);
        return 1;
    }

    return 0;
}
Example #6
0
IO_METHOD(IoSeq, removeAt)
{
	/*doc Sequence removeAt(index)
	Removes the item at index. Returns self.
	*/

	long i = IoMessage_locals_longArgAt_(m, locals, 0);

	IO_ASSERT_NOT_SYMBOL(self);

	i = UArray_wrapPos_(DATA(self), i);

	UArray_removeRange(DATA(self), i, 1);
	return self;
}
Example #7
0
void UArray_replaceAnyCase_with_(UArray *self, const UArray *a1, const UArray *a2)
{
    long i;
    size_t start = 0;
    UArray visible = UArray_stackRange(self, start, self->size);

    while ((i = UArray_findAnyCase_(&visible, a1)) != -1)
    {
        size_t index = start + i;
        UArray_removeRange(self, index, a1->size);
        UArray_at_putAll_(self, index, a2);
        start = index + a2->size;
        visible = UArray_stackRange(self, start, self->size - start);
    }

    UArray_changed(self);
}
Example #8
0
IO_METHOD(IoSeq, removeSlice)
{
	/*doc Sequence removeSlice(startIndex, endIndex)
	Removes the items from startIndex to endIndex.
	Returns self.
	*/

	long start = IoMessage_locals_longArgAt_(m, locals, 0);
	long end   = IoMessage_locals_longArgAt_(m, locals, 1);

	IO_ASSERT_NOT_SYMBOL(self);

	start = UArray_wrapPos_(DATA(self), start);
	end   = UArray_wrapPos_(DATA(self), end);

	UArray_removeRange(DATA(self), start, end - start + 1);
	return self;
}
Example #9
0
BASEKIT_API int UArray_clipBeforeEndOf_(UArray *self, const UArray *other)
{
    long index = UArray_find_(self, other);
    /*
    printf("UArray_find_('%s', '%s')\n", UArray_bytes(self), UArray_bytes(other));
    printf("find index = %i\n", index);
    printf("prefix sizeInBytes = %i\n", UArray_sizeInBytes(other));
    printf("prefix size = %i\n", UArray_size(other));
    */
    if (index > -1 && other->size)
    {
        //printf("UArray_removeRange(0, %i)\n", index + other->size - 1);
        UArray_removeRange(self, 0, index + other->size);
        //printf("result = '%s'\n", UArray_bytes(self));
        return 1;
    }

    return 0;
}
Example #10
0
IoObject *IoBlowfish_process(IoBlowfish *self, IoObject *locals, IoMessage *m)
{
	/*doc Blowfish process
	Process the inputBuffer and appends the result to the outputBuffer.
	The processed inputBuffer is empties except for the spare 
	bytes at the end which don't fit into a cipher block.
	*/
	blowfish_ctx *context = &(DATA(self)->context);
	int isEncrypting = DATA(self)->isEncrypting;

	UArray *input = IoObject_rawGetMutableUArraySlot(self, locals, m, IOSYMBOL("inputBuffer"));
	UArray *output = IoObject_rawGetMutableUArraySlot(self, locals, m, IOSYMBOL("outputBuffer"));

	const unsigned char *inputBytes  = (uint8_t *)UArray_bytes(input);
	size_t inputSize = UArray_sizeInBytes(input);

	unsigned long lr[2];
	size_t i, runs = inputSize / sizeof(lr);

	for (i = 0; i < runs; i ++)
	{
		memcpy(lr, inputBytes, sizeof(lr));

		inputBytes += sizeof(lr);

		if (isEncrypting)
		{
			blowfish_encrypt(context, &lr[0], &lr[1]);
		}
		else
		{
			blowfish_decrypt(context, &lr[0], &lr[1]);
		}

		UArray_appendBytes_size_(output, (unsigned char *)&lr, sizeof(lr));
	}

	UArray_removeRange(input, 0, runs * sizeof(lr));
	return self;
}
Example #11
0
File: IoSocket.c Project: BMeph/io
IoObject *IoSocket_asyncUdpWrite(IoSocket *self, IoObject *locals, IoMessage *m)
{
	/*doc Socket asyncUdpWrite(ipAddress, aSeq, startIndex, readSize) 
	Writes readsize bytes from aSeq starting at startIndex to ipAddress. 
	Returns self immediately if successful. Returns an error object on Error. Returns nil if the socket is disconnected.
	*/
	
	IoObject *address = IoMessage_locals_addressArgAt_(m, locals, 0);
	UArray *buffer = IoSeq_rawUArray(IoMessage_locals_seqArgAt_(m, locals, 1));
	size_t start = IoMessage_locals_intArgAt_(m, locals, 2);
	size_t writeSize = IoMessage_locals_intArgAt_(m, locals, 3);
	size_t bytesWritten = Socket_udpWrite(SOCKET(self), IoSocket_rawAddressFrom_(address), buffer, start, writeSize);
	
	if (bytesWritten)
	{
		if (bytesWritten < writeSize)
		{
			return SOCKETERROR("Socket udp write failed");
		}
		else
		{
			UArray_removeRange(buffer, start, bytesWritten);
			return self;
		}
	}
	else
	{
		if (Socket_asyncFailed())
		{
			return SOCKETERROR("Socket udp write failed");
		}
		else
		{
			return IONIL(self);
		}
	}
}
Example #12
0
File: IoSocket.c Project: BMeph/io
IoObject *IoSocket_asyncStreamWrite(IoSocket *self, IoObject *locals, IoMessage *m)
{
	/*doc Socket asyncStreamWrite(aSeq, start, writeSize) 
	Writes the slice of aSeq from start to start + writeSize to the socket.
	Returns self immediately if successful, otherwise closes the socket. 
	Returns an error object on Error. 
	Returns nil if the socket is disconnected.
	*/
	
	IoSeq *bufferSeq = IoMessage_locals_seqArgAt_(m, locals, 0);
	UArray *buffer = IoSeq_rawUArray(bufferSeq);
	size_t start = IoMessage_locals_intArgAt_(m, locals, 1);
	size_t writeSize = IoMessage_locals_intArgAt_(m, locals, 2);
	size_t bytesWritten = Socket_streamWrite(SOCKET(self), buffer, start, writeSize);
	
	if (bytesWritten)
	{
		UArray_removeRange(buffer, start, bytesWritten);
		return self;
	}
	else
	{
		if (Socket_asyncFailed())
		{
			IoSocket_close(self, locals, m);
			return SOCKETERROR("Socket stream write failed");
		}
		else
		{
			int errorNumber = SocketErrorStatus();
			
			if (errorNumber == ECONNRESET) IoSocket_close(self, locals, m);
			return IONIL(self);
		}
	}
}