示例#1
0
文件: IoDBI.c 项目: BMeph/io
IoObject *IoDBI_drivers(IoDBI *self, IoObject *locals, IoMessage *m)
{
	/*doc DBI drivers
	Get a list of drivers and its associated information:

	<ol>
		<li>name</li>
		<li>description</li>
		<li>filename</li>
		<li>version</li>
		<li>date compiled</li>
		<li>maintainer</li>
		<li>url</li>
	</ol>
	*/
	IoList *list = IOREF(IoList_new(IOSTATE));
	dbi_driver driver = NULL;

	while((driver = dbi_driver_list(driver)) != NULL)
	{
		IoList *dlist = IOREF(IoList_new(IOSTATE));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_name(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_description(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_filename(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_version(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_date_compiled(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_maintainer(driver)));
		IoList_rawAppend_(dlist, IOSYMBOL(dbi_driver_get_url(driver)));

		IoList_rawAppend_(list, dlist);
	}

	return list;
}
示例#2
0
文件: IoRegexMatch.c 项目: ADTSH/io
IoRegexMatch *IoRegexMatch_newWithRegex_subject_captureRanges_(void *state, IoRegex *regex, IoSymbol *subject, IoList *captureRanges)
{
	IoRegexMatch *self = IOCLONE(IoState_protoWithId_(state, protoId));
	DATA(self)->regex = IOREF(regex);
	DATA(self)->subject = IOREF(subject);
	DATA(self)->ranges = captureRanges;
	return self;
}
示例#3
0
文件: IoRegexMatch.c 项目: ADTSH/io
IoRegexMatch *IoRegexMatch_rawClone(IoRegexMatch *proto)
{
	IoObject *self = IoObject_rawClonePrimitive(proto);
	IoObject_setDataPointer_(self, calloc(1, sizeof(IoRegexMatchData)));
	DATA(self)->subject = IOREF(DATA(proto)->subject);
	DATA(self)->regex = IOREF(DATA(proto)->regex);
	DATA(self)->ranges = IOREF(DATA(proto)->ranges);
	return self;
}
示例#4
0
文件: IoFile.c 项目: 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;
}
示例#5
0
文件: IoSyslog.c 项目: Akiyah/io
IoObject *IoSyslog_open(IoSyslog *self, IoObject *locals, IoMessage *m)
{
	/*doc Syslog open(aPriority, someOptions, optionalIdentity)
	Opens the syslog for writing. optionalIdentity need not be entered 
	and will default to the name of the distribution of Io you are running 
	or if you have embedded Io into your application and set 
	Lobby distribution = "foo", it will be set to "foo".
	*/
	 
	int syslog_facility, syslog_options;
	//int i, max;
	char *syslog_ident;

	if (DATA(self)->syslog_opened)
	{
		IoState_error_(IOSTATE, m, "System log is already open");
		return IONIL(self);
	}

	{
		DATA(self)->facility = IOREF(IoMessage_locals_numberArgAt_(m, locals, 0));
		if (ISNIL(DATA(self)->facility))
		{
			syslog_facility = LOG_USER;
		}
		else
		{
			syslog_facility = IoObject_dataUint32(DATA(self)->facility);
		}

		DATA(self)->options = IOREF(IoMessage_locals_listArgAt_(m, locals, 1));
		syslog_options = 0;
		if (ISNIL(DATA(self)->options))
		{
			syslog_options = LOG_PID | LOG_CONS;
		}
		else
		{
			List *list = IoList_rawList(DATA(self)->options);

			LIST_FOREACH(list, i, v,
				syslog_options |= (int)CNUMBER(v);
			);
		}

		syslog_ident = (char *)IOSYMBOL_BYTES(DATA(self)->ident);
		if ((strlen(syslog_ident) == 0) || ISNIL(DATA(self)->ident))
		{
			char *s = CSTRING(IoState_doCString_(IOSTATE, "Lobby distribution"));
			strncpy(syslog_ident, s, strlen(s));
		}

		openlog(syslog_ident, syslog_options, syslog_facility);
		DATA(self)->syslog_opened = 1;
		DATA(self)->syslog_mask = setlogmask(0);
		setlogmask(DATA(self)->syslog_mask);
	}
示例#6
0
void IoBlock_copy_(IoBlock *self, IoBlock *other)
{
	DATA(self)->message = IOREF(DATA(other)->message);

	{
		List *l1 = DATA(self)->argNames;
		List_removeAll(l1);
		LIST_FOREACH(DATA(other)->argNames, i, v, List_append_(l1, IOREF(v)); );
	}
示例#7
0
文件: IoFile.c 项目: achoy/io
IO_METHOD(IoFile, standardInput)
{
	/*doc File standardInput
	Returns a new File whose stream is set to the standard input stream.
	*/

	IoFile *newFile = IoFile_new(IOSTATE);
	DATA(newFile)->path = IOREF(IOSYMBOL("<standard input>"));
	DATA(newFile)->mode = IOREF(IOSYMBOL("r"));
	DATA(newFile)->stream = stdin;
	DATA(newFile)->flags = IOFILE_FLAGS_NONE;
	return newFile;
}
示例#8
0
文件: IoFile.c 项目: achoy/io
IO_METHOD(IoFile, standardError)
{
	/*doc File standardError
	Returns a new File whose stream is set to the standard error stream.
	*/

	IoFile *newFile = IoFile_new(IOSTATE);
	DATA(newFile)->path = IOREF(IOSYMBOL("<standard error>"));
	DATA(newFile)->mode = IOREF(IOSYMBOL("w"));
	DATA(newFile)->stream = stderr;
	DATA(newFile)->flags = IOFILE_FLAGS_NONE;
	return newFile;
}
示例#9
0
文件: IoRegexMatches.c 项目: ADTSH/io
IoRegexMatches *IoRegexMatches_rawClone(IoRegexMatches *proto)
{
	IoObject *self = IoObject_rawClonePrimitive(proto);
	IoObject_setDataPointer_(self, calloc(1, sizeof(IoRegexMatchesData)));

	if (!ISNIL(DATA(proto)->regex))
		DATA(self)->regex = IOREF(DATA(proto)->regex);
	else
		DATA(self)->regex = IONIL(self);
	DATA(self)->string = IOREF(DATA(proto)->string);

	DATA(self)->captureArray = UArray_clone(DATA(proto)->captureArray);
	return self;
}
示例#10
0
文件: IoCFFIArray.c 项目: bomma/io
IoCFFIArray *IoCFFIArray_atPut(IoCFFIArray *self, IoObject *locals, IoMessage *m)
{
	int pos;
	IoObject *value, *arrayType, *d;
	char *ptr;

	pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));
	value = IoMessage_locals_valueArgAt_(m, locals, 1);

	if ( pos >= DATA(self)->arraySize ) {
		IoState_error_(IOSTATE, m, "index out of bounds");
		return IONIL(self);
	}

	arrayType = IoObject_getSlot_(self, IOSYMBOL("arrayType"));
	ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos);

	d = IOCLONE(arrayType);
	IoCFFIDataType_rawSetValue(d, value);
	memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(self, d), DATA(self)->itemSize);

	if ( DATA(self)->keepValuesRefs ) {
		DATA(self)->keepValuesRefs[pos] = IOREF(d);
	}

	return self;
}
示例#11
0
文件: IoRegex.c 项目: ADTSH/io
IoRegex *IoRegex_rawClone(IoRegex *proto)
{
	IoObject *self = IoObject_rawClonePrimitive(proto);
	IoObject_setDataPointer_(self, calloc(1, sizeof(IoRegexData)));
	DATA(self)->pattern = IOREF(DATA(proto)->pattern);
	return self;
}
示例#12
0
文件: IoSQLite3.c 项目: JoeyButler/io
IoObject *IoSQLite3_execWithCallback(IoSQLite3 *self,
									 IoObject *locals, IoMessage *m, IoSymbol *s, ResultRowCallback *callback)
{
	IoList *results;

	if (!DATA(self)->db)
	{
		IoSQLite3_justOpen(self);

		if (!DATA(self)->db)
		{
			return IONIL(self);
		}
	}

	DATA(self)->results = IOREF(IoList_new(IOSTATE));

	if (DATA(self)->debugOn)
	{
		IoState_print_(IOSTATE, "*** %s ***\n", CSTRING(s));
	}

	{
		char *zErrMsg;
		sqlite3_exec(DATA(self)->db, CSTRING(s), callback, self, &zErrMsg);

		IoSQLite3_showError(self);
	}

	results = DATA(self)->results;
	DATA(self)->results = NULL;
	return results;
}
示例#13
0
文件: IoRegex.c 项目: ADTSH/io
IoObject *IoRegex_namedCaptures(IoRegex *self, IoObject *locals, IoMessage *m)
{
	/*doc Regex namedCaptures
	Returns a Map that contains the index of each named group.
	*/
	
	IoMap *map = DATA(self)->namedCaptures;
	NamedCapture *namedCaptures = 0, *capture = 0;

	if (map)
		return map;

	map = DATA(self)->namedCaptures = IOREF(IoMap_new(IOSTATE));

	capture = namedCaptures = Regex_namedCaptures(IoRegex_rawRegex(self));
	
	if (!namedCaptures)
		return map;

	while (capture->name) 
	{
		IoMap_rawAtPut(map, IOSYMBOL(capture->name), IONUMBER(capture->index));
		capture++;
	}
	
	free(namedCaptures);
	return map;
}
示例#14
0
文件: IoFile.c 项目: achoy/io
IO_METHOD(IoFile, reopen)
{
	/*doc File reopen(otherFile, mode)
	Reopens otherFile and redirects its stream to this file's path using mode.
	If mode is omitted, it is copied from otherFile.
	Returns self or raises a File exception on error.
	*/

	IoFile *otherFile;
	IoSeq *mode;

	DATA(self)->flags = IOFILE_FLAGS_NONE;

	IoMessage_assertArgCount_receiver_(m, 1, self);
	
	otherFile = IoMessage_locals_valueArgAt_(m, locals, 0);
	IOASSERT(ISFILE(otherFile), "arg must be a File");
	
	mode = IoMessage_locals_valueArgAt_(m, locals, 1);
	if(ISSEQ(mode))
	{
		DATA(self)->mode = IOREF(mode);
	}
	else
	{
		DATA(self)->mode = IOREF(IoSeq_newWithUArray_copy_(IOSTATE, (UArray *)DATA(DATA(otherFile)->mode), 1));
	}

	if (!DATA(self)->stream)
	{
		FILE *fp = freopen(UTF8CSTRING(DATA(self)->path), CSTRING(DATA(self)->mode), DATA(otherFile)->stream);

		if (fp)
		{
			DATA(self)->stream = fp;
		}
		else
		{
			printf("%i:%s\n", errno, strerror(errno));
			IoState_error_(IOSTATE, m, "unable to reopen to file '%s' with mode %s.", UTF8CSTRING(DATA(self)->path), CSTRING(DATA(self)->mode));
			fclose(fp);
		}
	}

	return self;
}
示例#15
0
文件: IoFnmatch.c 项目: anthem/io
IoObject *IoFnmatch_setString(IoFnmatch *self, IoObject *locals, IoMessage *m)
{
	/*doc Fnmatch setString(aString)
	Sets the string to do matching on.
	*/

	DATA(self)->string = IOREF(IoMessage_locals_symbolArgAt_(m, locals, 0));
	return self;
}
示例#16
0
文件: IoFnmatch.c 项目: anthem/io
IoObject *IoFnmatch_setPattern(IoFnmatch *self, IoObject *locals, IoMessage *m)
{
	/*doc Fnmatch setPattern(aString)
	Sets the pattern string. Returns self.
	*/

	DATA(self)->pattern = IOREF(IoMessage_locals_symbolArgAt_(m, locals, 0));
	return self;
}
示例#17
0
文件: IoFile.c 项目: achoy/io
IO_METHOD(IoFile, openForReading)
{
	/*doc File openForReading(optionalPathString)
	Sets the file mode to read (reading only) and calls open(optionalPathString). 
	*/
	
	DATA(self)->mode = IOREF(IOSYMBOL("r"));
	return IoFile_open(self, locals, m);
}
示例#18
0
文件: IoFont.c 项目: Teslos/io
IoObject *IoFont_setPath(IoFont *self, IoObject *locals, IoMessage *m)
{
	/*doc Font setPath(aString)
	Sets the Font path. Returns self.
	*/

	DATA(self)->path = IOREF(IoMessage_locals_seqArgAt_(m, locals, 0));
	return self;
}
示例#19
0
文件: IoSQLite3.c 项目: JoeyButler/io
IoObject *IoSQLite3_setPath(IoSQLite3 *self, IoObject *locals, IoMessage *m)
{
	/*doc SQLite3 setPath
	Sets the path to the database file. Returns self. 
	*/

	DATA(self)->path = IOREF(IoMessage_locals_symbolArgAt_(m, locals, 0));
	return self;
}
示例#20
0
文件: IoFile.c 项目: achoy/io
IO_METHOD(IoFile, openForAppending)
{
	/*doc File openForAppending(optionalPathString)
	Sets the file mode to append (writing to the end of the file)
	and calls open(optionalPathString).
	*/

	DATA(self)->mode = IOREF(IOSYMBOL("a+"));
	return IoFile_open(self, locals, m);
}
示例#21
0
void IoMessage_parseName(IoMessage *self, IoLexer *lexer)
{
	IoToken *token = IoLexer_pop(lexer);

	DATA(self)->name = IOREF(IOSYMBOL(IoToken_name(token)));

	IoMessage_ifPossibleCacheToken_(self, token);
	IoMessage_rawSetLineNumber_(self, IoToken_lineNumber(token));
	IoMessage_rawSetCharNumber_(self, IoToken_charNumber(token));
}
示例#22
0
文件: IoRegexMatches.c 项目: ADTSH/io
IoObject *IoRegexMatches_setString(IoRegexMatches *self, IoObject *locals, IoMessage *m)
{
	/*doc RegexMatches setString(aString)
	Sets the string to find matches in. Returns self.
	*/
	DATA(self)->string = IOREF(IoMessage_locals_symbolArgAt_(m, locals, 0));
	DATA(self)->endPosition = IoSeq_rawSize(DATA(self)->string);
	IoRegexMatches_rawsetPosition_(self, 0);
	return self;
}
示例#23
0
文件: IoFile.c 项目: achoy/io
IO_METHOD(IoFile, setPath)
{
	/*doc File setPath(aString)
	Sets the file path of the receiver to pathString.
	The default path is an empty string. Returns self.
	*/

	DATA(self)->path = IOREF(IoMessage_locals_symbolArgAt_(m, locals, 0));
	return self;
}
示例#24
0
void IoMessage_rawSetNext_(IoMessage *self, IoMessage *m)
{
	DATA(self)->next = m ? IOREF(m) : NULL;

#ifdef IOMESSAGE_HASPREV
	if(m)
	{
		DATA(m)->previous = self;
	}
#endif
}
示例#25
0
文件: IoFile.c 项目: achoy/io
IO_METHOD(IoFile, openForUpdating)
{
	/*doc File openForUpdating(optionalPathString)
	Sets the file mode to update (reading and writing) and calls
	open(optionalPathString). This will not delete the file if it already exists.
	Use the remove method first if you need to delete an existing file before opening a new one.
	*/

	DATA(self)->mode = IOREF(IOSYMBOL("r+"));
	return IoFile_open(self, locals, m);
}
示例#26
0
文件: IoFile.c 项目: achoy/io
IO_METHOD(IoFile, popen)
{
	/*doc File popen
	Open the file as a pipe. Return self.

	Closing a popen'ed file sets exitStatus or termSignal
	to reflect the status or cause of the child processes' termination.
	*/

	DATA(self)->flags = IOFILE_FLAGS_PIPE;

	if (IoMessage_argCount(m) > 0)
	{
		DATA(self)->path = IOREF(IoMessage_locals_symbolArgAt_(m, locals, 0));
	}

	if (DATA(self)->stream)
	{
		IoFile_justClose(self);
	}

#if defined(SANE_POPEN)
	DATA(self)->mode = IOREF(IOSYMBOL("a+"));
	DATA(self)->stream = popen(UTF8CSTRING(DATA(self)->path), "r+");
#elif defined(__SYMBIAN32__)
	/* Symbian does not implement popen.
		* (There is popen3() but it is "internal and not intended for use.")
		*/
	DATA(self)->mode = IOREF(IOSYMBOL("r"));
	DATA(self)->stream = NULL;
#else
	DATA(self)->mode = IOREF(IOSYMBOL("r"));
	DATA(self)->stream = popen(UTF8CSTRING(DATA(self)->path), "r");
#endif
	if (DATA(self)->stream == NULL)
	{
		IoState_error_(IOSTATE, m, "error executing file path '%s'", UTF8CSTRING(DATA(self)->path));
	}

	return self;
}
示例#27
0
void IoMessage_setCachedArg_toInt_(IoMessage *self, int n, int anInt)
{
	// optimized to avoid creating a number unless necessary

	IoMessage *arg = NULL;

	while (!(arg = List_at_(DATA(self)->args, n)))
	{
		List_append_(DATA(self)->args, IOREF(IoMessage_new(IOSTATE)));
	}

	IoMessage_rawSetCachedResult_(arg, IONUMBER(anInt));
}
示例#28
0
文件: IoFont.c 项目: Teslos/io
IoObject *IoFont_open(IoFont *self, IoObject *locals, IoMessage *m)
{
	/*doc Font open(optionalPath)
	Opens the font. Sets path using optionalPath if supplied. Returns self.
	*/

	if (IoMessage_argCount(m) > 0)
	{
		DATA(self)->path = IOREF(IoMessage_locals_seqArgAt_(m, locals, 0));
	}

	GLFont_loadFont( DATA(self)->font, CSTRING(DATA(self)->path) );
	IoFont_checkError(self, locals, m);
	return self;
}
示例#29
0
IO_METHOD(IoDirectory, setPath)
{
    /*doc Directory setPath(aString)
    Sets the directory path. Returns self.
    */

    DATA(self)->path = IOREF(IoMessage_locals_symbolArgAt_(m, locals, 0));

    /*
    {
    	UArray *path = IoSeq_rawUArray(DATA(self)->path);
    	printf("IoDirectory_setPath path = \"%s\" %i\n", UArray_asCString(path), UArray_itemSize(path));
    }
    */
    return self;
}
示例#30
0
文件: IoSQLite.c 项目: Akiyah/io
IoObject *IoSQLite_execWithCallback(IoSQLite *self,
									IoObject *locals,
									IoMessage *m,
									IoSymbol *s,
									ResultRowCallback *callback)
{
	IoList *results;

	if (!DATA(self)->db)
	{
		IoSQLite_open(self, locals, m);

		if (!DATA(self)->db)
		{
			return IONIL(self);
		}
	}

	DATA(self)->results = IOREF(IoList_new(IOSTATE));

	if (DATA(self)->debugOn)
	{
		IoState_print_(IOSTATE, "*** %s ***\n", CSTRING(s));
	}

	{
		char *zErrMsg;
		int rc = sqlite_exec(DATA(self)->db, CSTRING(s), callback, self, &zErrMsg);

		if (rc != SQLITE_OK)
		{
			IoSQLite_error_(self, zErrMsg);
			IoState_error_(IOSTATE, m, zErrMsg);
		}
		else
		{
			IoSQLite_error_(self, "");
		}
	}

	results = DATA(self)->results;
	DATA(self)->results = NULL;
	return results;
}