Exemplo n.º 1
0
Arquivo: IoFile.c Projeto: achoy/io
void *IoFile_readFromStream_(IoFile *self, BStream *stream)
{
	IoSymbol *mode;
	IoSymbol *path = IoState_symbolWithUArray_copy_(IOSTATE, BStream_readTaggedUArray(stream), 1);
	DATA(self)->path = IOREF(path);
	mode = IoState_symbolWithUArray_copy_(IOSTATE, BStream_readTaggedUArray(stream), 1);
	DATA(self)->mode = IOREF(mode);
	return self;
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
IO_METHOD(IoSeq, inclusiveSlice)
{
	/*doc Sequence inclusiveSlice(inclusiveStartIndex, inclusiveEndIndex)
	Returns a new string containing the subset of the
	receiver from the inclusiveStartIndex to the inclusiveEndIndex. The inclusiveEndIndex argument
	is optional. If not given, it is assumed to be the end of the string. 
	*/

	long fromIndex = IoMessage_locals_longArgAt_(m, locals, 0);
	long last = UArray_size(DATA(self));
	UArray *ba;

	if (IoMessage_argCount(m) > 1)
	{
		last = IoMessage_locals_longArgAt_(m, locals, 1);
	}

	if (last == -1)
	{
		last = UArray_size(DATA(self));
	}
	else
	{
		last = last + 1;
	}
	
	ba = UArray_slice(DATA(self), fromIndex, last);

	if (ISSYMBOL(self))
	{
		return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
	}

	return IoSeq_newWithUArray_copy_(IOSTATE, ba, 0);
}
Exemplo n.º 4
0
IoSymbol *IoState_symbolWithCString_length_(IoState *self, const char *s, size_t length)
{
	UArray *a = UArray_newWithData_type_size_copy_((char *)s, CTYPE_uint8_t, length, 1);
	UArray_setEncoding_(a, CENCODING_UTF8);
	UArray_convertToFixedSizeType(a);
	return IoState_symbolWithUArray_copy_(self, a, 0);
}
Exemplo n.º 5
0
IoSymbol *IoSeq_rawAsUntriquotedSymbol(IoSeq *self)
{
	UArray *a = UArray_clone(DATA(self));
	UArray_unquote(a);
	UArray_unquote(a);
	UArray_unquote(a);
	return IoState_symbolWithUArray_copy_(IOSTATE, a, 0);
}
Exemplo n.º 6
0
IO_METHOD(IoMessage, descriptionString)
{
	/*doc Message code
	Returns a String containing a decompiled code representation of the receiver.
	*/

	UArray *ba = IoMessage_description(self); /* me must io_free the returned UArray */
	return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
}
Exemplo n.º 7
0
IoSymbol *IoSeq_newSymbolWithFormat_(void *state, const char *format, ...)
{
	UArray *ba;
	va_list ap;
	va_start(ap, format);
	ba = UArray_newWithVargs_(format, ap);
	va_end(ap);
	return IoState_symbolWithUArray_copy_(state, ba, 0);
}
Exemplo n.º 8
0
IoObject *IoSeq_rawAsSymbol(IoSeq *self)
{
	if (ISSYMBOL(self))
	{
		return self;
	}

	return IoState_symbolWithUArray_copy_(IOSTATE, DATA(self), 1);
}
Exemplo n.º 9
0
IO_METHOD(IoDirectory, currentWorkingDirectory)
{
    /*doc Directory currentWorkingDirectory
    Returns the current working directory path.
    */

    return IoState_symbolWithUArray_copy_(IOSTATE,
                                          IoDirectory_CurrentWorkingDirectoryAsUArray(), 0);
}
Exemplo n.º 10
0
Arquivo: IoSHA1.c Projeto: ADTSH/io
IoObject *IoSHA1_sha1String(IoSHA1 *self, IoObject *locals, IoMessage *m)
{
	/*doc SHA1 sha1String
	Returns a string containing a hexadecimal representation of the sha1 hash.
	*/
	
	UArray *ba = IoSHA1_sha1UArray(self);
	UArray *baString = UArray_asNewHexStringUArray(ba);
	UArray_free(ba);
	return IoState_symbolWithUArray_copy_(IOSTATE, baString, 0);
}
Exemplo n.º 11
0
Arquivo: IoDate.c Projeto: bomma/io
IO_METHOD(IoDate, asString)
{
	/*doc Date asString(optionalFormatString)
	Returns a string representation of the receiver using the
receivers format. If the optionalFormatString argument is present, the
receiver's format is set to it first. Formatting is according to ANSI C
date formatting rules.
<p>
<pre>	
%a abbreviated weekday name (Sun, Mon, etc.)
%A full weekday name (Sunday, Monday, etc.)
%b abbreviated month name (Jan, Feb, etc.)
%B full month name (January, February, etc.)
%c full date and time string
%d day of the month as two-digit decimal integer (01-31)
%H hour as two-digit 24-hour clock decimal integer (00-23)
%I hour as two-digit 12-hour clock decimal integer (01-12)
%m month as a two-digit decimal integer (01-12)
%M minute as a two-digit decimal integer (00-59)
%p either "AM" or "PM"
%S second as a two-digit decimal integer (00-59)
%U number of week in the year as two-digit decimal integer (00-52)
with Sunday considered as first day of the week
%w weekday as one-digit decimal integer (0-6) with Sunday as 0
%W number of week in the year as two-digit decimal integer (00-52)
with Monday considered as first day of the week
%x full date string (no time); in the C locale, this is equivalent
to "%m/%d/%y".
%y year without century as two-digit decimal number (00-99)
%Y year with century as four-digit decimal number
%Z time zone name (e.g. EST);
null string if no time zone can be obtained
%% stands for '%' character in output string.
</pre>	
*/

	char *format = "%Y-%m-%d %H:%M:%S %Z";

	if (IoMessage_argCount(m) == 1)
	{
		format = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0));
	}
	else
	{
		IoObject *f = IoObject_getSlot_(self, IOSYMBOL("format"));
		if (ISSEQ(f)) { format = CSTRING(f); }
	}

	{
		UArray *ba = Date_asString(DATA(self), format);
		return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
	}
}
Exemplo n.º 12
0
IoObject *IoSQLite3_escapeString(IoSQLite3 *self, IoObject *locals, IoMessage *m)
{
	/*doc SQLite3 escapeString(aString)
	Returns a translated version of aString by making two copies of 
	every single-quote (') character. This has the effect of escaping the 
	end-of-string meaning of single-quote within a string literal.
	*/

	IoSymbol *s = IoMessage_locals_seqArgAt_(m, locals, 0);
	char *newString = sqlite3_mprintf("%q", CSTRING(s));
	UArray *ba = UArray_newWithCString_(newString);
	sqlite3_free(newString);
	return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
}
Exemplo n.º 13
0
IoSymbol *IoSeq_rawAsUnquotedSymbol(IoSeq *self)
{
	UArray *a = UArray_clone(DATA(self));
	/*
	UArray *sa = DATA(self);
	UArray *a = UArray_new();
	UArray_setItemType_(a, UArray_itemType(sa));
	UArray_setEncoding_(a, UArray_encoding(sa));
	UArray_setSize_(a, UArray_size(sa));
	UArray_copy_(a, sa);
	*/
	UArray_unquote(a);
	return IoState_symbolWithUArray_copy_(IOSTATE, a, 0);
}
Exemplo n.º 14
0
Arquivo: IoFile.c Projeto: achoy/io
IO_METHOD(IoFile, readStringOfLength_)
{
	/*doc File readStringOfLength(aNumber)
	Reads a String of the specified length and returns it.
	Returns Nil if the end of the file has been reached.
	*/

	UArray *ba = IoFile_readUArrayOfLength_(self, locals, m);

	if (!ba)
	{
		return IONIL(self);
	}

	return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
}
Exemplo n.º 15
0
Arquivo: IoFile.c Projeto: achoy/io
IoObject *IoFile_rawAsString(IoFile *self)
{
	UArray *ba = UArray_new();

	if (UArray_readFromFilePath_(ba, IoSeq_rawUArray(DATA(self)->path)) == 1)
	{
		return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
	}
	else
	{
		UArray_free(ba);
		IoState_error_(IOSTATE, NULL, "unable to read file '%s'", UTF8CSTRING(DATA(self)->path));
	}

	return IONIL(self);
}
Exemplo n.º 16
0
void IoState_error_(IoState *self, IoMessage *m, const char *format, ...)
{
	IoSymbol *description;

	va_list ap;
	va_start(ap, format);
	description = IoState_symbolWithUArray_copy_(self, UArray_newWithVargs_(format, ap), 0);
	va_end(ap);

	/*
	fputs("\nIoState_error_: ", stderr);
	fputs(CSTRING(description), stderr);
	fputs("\n\n", stderr);
	*/

	{
		IoCoroutine *coroutine = IoState_currentCoroutine(self);
		IoCoroutine_raiseError(coroutine, description, m);
	}
}
Exemplo n.º 17
0
IO_METHOD(IoSeq, with)
{
	/*doc Sequence with(aSequence, ...)
	Returns a new Sequence which is the concatination of the arguments.
	The returned sequence will have the same mutability status as the receiver.
	*/

	int n, argCount = IoMessage_argCount(m);
	UArray *ba = UArray_clone(DATA(self));

	for (n = 0; n < argCount; n ++)
	{
		IoSeq *v = IoMessage_locals_seqArgAt_(m, locals, n);
		UArray_append_(ba, DATA(v));
	}

	if (ISSYMBOL(self))
	{
		return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
	}

	return IoSeq_newWithUArray_copy_(IOSTATE, ba, 0);
}
Exemplo n.º 18
0
IoObject *IoDirectory_justFullPath(IoDirectory *self, IoSymbol *name)
{
    UArray *fullPath = UArray_clone(IoSeq_rawUArray(DATA(self)->path));
    UArray_appendPath_(fullPath, IoSeq_rawUArray(name));
    return IoState_symbolWithUArray_copy_(IOSTATE, fullPath, 0);
}