コード例 #1
0
IoObject *IoDirectory_itemForDirent_(IoDirectory *self, struct dirent *dp)
{
    IoSymbol *pathString;
    int isDir;
    UArray *path = IoSeq_rawUArray(DATA(self)->path);
    UArray *ba = UArray_clone(path);

    /*
    printf("IoDirectory_itemForDirent_ path = \"%s\" %i\n", p, path->itemSize);
    printf("IoDirectory_itemForDirent_ ba = \"%s\" %i\n", UArray_asCString(ba), ba->itemSize);
    */
    if (UArray_size(ba) && !IS_PATH_SEPERATOR(UArray_longAt_(ba, UArray_size(ba) - 1)))
    {
        UArray_appendCString_(ba, IO_PATH_SEPARATOR);
    }

    UArray_appendCString_(ba, dp->d_name);
    pathString = IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);

    isDir = isDirectory(dp, CSTRING(pathString));

    if (isDir)
    {
        return IoDirectory_newWithPath_(IOSTATE, pathString);
    }

    return IoFile_newWithPath_(IOSTATE, pathString);
}
コード例 #2
0
ファイル: UArray_math.c プロジェクト: eklitzke/io
UArray *UArray_asBits(const UArray *self)
{
	UArray *out = UArray_new();
	size_t i, max = UArray_sizeInBytes(self);
	uint8_t *data = self->data;

	for (i = 0; i < max; i ++)
	{
		uint8_t b = data[i];
		int j;

		for (j = 0; j < 8; j ++)
		{
			int v = (b >> j) & 0x1;
			UArray_appendCString_(out, v ? "1" : "0");
		}
	}

	return out;
}
コード例 #3
0
ファイル: IoTokyoCabinetPrefixCursor.c プロジェクト: ADTSH/io
IoObject *IoTokyoCabinetPrefixCursor_last(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc TokyoCabinetPrefixCursor last
	Move cursor to last record. Returns self
	*/

	IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix"));
	IOASSERT(ISSEQ(prefix), "prefix must be a sequence");
	IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor");
	
	{
		UArray *p = UArray_clone(IoSeq_rawUArray(prefix));
		UArray_appendCString_(p, " "); // space preceeds .
		
		tcbdbcurjump(TokyoCabinetPrefixCursor(self), (const void *)UArray_bytes(p), (int)UArray_size(p));
		
		UArray_free(p);
	}
	
	return IOBOOL(self, IoTokyoCabinetPrefixCursor_keyBeginsWithPrefix_(self, prefix));
}
コード例 #4
0
ファイル: IoMessage.c プロジェクト: mikedouglas/io
void IoMessage_appendDescriptionTo_follow_(IoMessage *self, UArray *ba, int follow)
{
	do {
		IoMessageData *data = DATA(self);

		UArray_appendCString_(ba, CSTRING(data->name));

		{
			size_t i, max = List_size(DATA(self)->args);

			if (max > 0)
			{
				UArray_appendCString_(ba, "(");

				for (i = 0; i < max; i ++)
				{
					IoMessage *arg = List_at_(DATA(self)->args, i);
					IoMessage_appendDescriptionTo_follow_(arg, ba, 1);

					if (i != max - 1)
					{
						UArray_appendCString_(ba, ", ");
					}
				}

				UArray_appendCString_(ba, ")");
			}
		}

		if (!follow)
		{
			return;
		}

		if (DATA(self)->next && DATA(self)->name != IOSTATE->semicolonSymbol) UArray_appendCString_(ba, " ");
		if (DATA(self)->name == IOSTATE->semicolonSymbol) UArray_appendCString_(ba, "\n");
	} while ((self = DATA(self)->next));
}