Exemplo n.º 1
0
IO_METHOD(IoDirectory, exists)
{
    /*doc Directory exists(optionalPath)
    Returns true if the Directory path exists, and false otherwise.
    If optionalPath string is provided, it tests the existence of that path instead.
    */

    IoSymbol *path = DATA(self)->path;
    DIR *dirp;

    if (IoMessage_argCount(m) > 0)
    {
        path = IoMessage_locals_symbolArgAt_(m, locals, 0);
    }

#if !defined(_WIN32) || defined(__CYGWIN__)
    dirp = opendir(CSTRING(path));

    if (!dirp)
    {
        return IOFALSE(self);
    }

    (void)closedir(dirp);
    return IOTRUE(self);
#else
    {
        DWORD d = GetFileAttributes(CSTRING(path));
        return (d != INVALID_FILE_ATTRIBUTES) && (d & FILE_ATTRIBUTE_DIRECTORY) ? IOTRUE(self) : IOFALSE(self);
    }
#endif
}
Exemplo n.º 2
0
IO_METHOD(IoObject, shellExecute)
{
	LPCTSTR operation;
	LPCTSTR file;
	LPCTSTR parameters;
	LPCTSTR directory;
	int displayFlag;
	int result;

	operation = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0));
	file = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 1));
	parameters = IoMessage_argCount(m) > 2 ? CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 2)) : NULL;
	directory = IoMessage_argCount(m) > 3 ? CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 3)) : NULL;
	displayFlag = IoMessage_argCount(m) > 4 ? IoMessage_locals_intArgAt_(m, locals, 4) : SW_SHOWNORMAL;

	result = (int)ShellExecute(NULL, operation, file, parameters, directory, displayFlag);

	if(result > 32)
	{
		return self;
	}
	else
	{
		return (IoObject *)IoError_newWithMessageFormat_(IOSTATE, "ShellExecute Error %i", result);
	}
}
Exemplo n.º 3
0
IO_METHOD(IoDirectory, createSubdirectory)
{
    /*doc Directory createSubdirectory(name)
    Create a subdirectory with the specified name.
    */

    IoState *state = IOSTATE;
    IoSymbol *subfolderName = IoMessage_locals_symbolArgAt_(m, locals, 0);
    IoObject *currentItem = IoDirectory_justAt(self, subfolderName);

    if (ISDIRECTORY(currentItem))
    {
        return currentItem;
    }

    if (ISFILE(currentItem))
    {
        IoState_error_(IOSTATE, m, "Attempt to create directory %s on top of existing file",
                       CSTRING(subfolderName));
    }
    else
    {
        IoSymbol *fullPath = IoDirectory_justFullPath(self, subfolderName);

        MKDIR(CSTRING(fullPath), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
        return IoDirectory_newWithPath_(state, fullPath);
    }

    return IONIL(self);
}
Exemplo n.º 4
0
IO_METHOD(IoDirectory, items)
{
    /*doc Directory items
    Returns a list object containing File and Directory objects
    for the files and directories of the receiver's path.
    */

    IoList *items = IoList_new(IOSTATE);
    IoDirectoryData *data = DATA(self);
    DIR *dirp = opendir(CSTRING(data->path));
    struct dirent *dp;

    if (!dirp)
    {
        IoState_error_(IOSTATE, m, "Unable to open directory %s", CSTRING(DATA(self)->path));
    }

    while ((dp = readdir(dirp)) != NULL)
    {
        IoList_rawAppend_(items, IoDirectory_itemForDirent_(self, dp));
    }

    (void)closedir(dirp);
    return items;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
static mlval add_external_ml_value(mlval arg)
{ char *str, *name;
  mlval item = MLUNIT;
  mlval current = external_ml_values;

  name = CSTRING(FIELD(arg,0));

  declare_root(&item, 0);
  declare_root(&current, 0);

  for(;;){
    if (MLISNIL(current)) break;
    
    item = MLHEAD(current);
    str  = CSTRING(FIELD(item,0));

    if (strcmp(name,str) == 0)
      { FIELD(item,1) = FIELD(arg,1);  /* Updates existing record */
        break;
      };

    item = MLUNIT;
    current = MLTAIL(current);
  };

  if (item == MLUNIT)
    { external_ml_values = cons(arg,external_ml_values); };

  retract_root(&item);
  retract_root(&current);

  return(MLUNIT);
}
Exemplo n.º 7
0
Arquivo: IoDBI.c Projeto: BMeph/io
IoObject *IoDBI_with(IoDBI *self, IoObject *locals, IoMessage *m)
{
	//doc DBI with(driverName) Get a new connection with the given driver.
	
	IoObject *name = IoMessage_locals_valueArgAt_(m, locals, 0);
	if (!ISSYMBOL(name))
	{
		IoState_error_(IOSTATE, m, "argument 0 to method '%s' must be a Symbol, not a '%s'\n",
			CSTRING(IoMessage_name(m)), IoObject_name(name));
		return IONIL(self);
	}

	if (DATA(self)->didInit != 1)
	{
		IoDBI_init(self, locals, m);
	}

	dbi_conn c = dbi_conn_new(CSTRING(name));
	if (c == NULL)
	{
		IoState_error_(IOSTATE, m, "libdbi error during dbi_conn_new\n");
		return IONIL(self);
	}

	return IoDBIConn_new(IOSTATE, c);
}
Exemplo n.º 8
0
Arquivo: IoDBI.c Projeto: BMeph/io
IoObject *IoDBI_initWithDriversPath(IoDBI *self, IoObject *locals,
			IoMessage *m)
{
	/*doc DBI initWithDriversPath 
	Initialize the DBI environment with the specified libdbi driver path.
	*/
	IoObject *dir = IoMessage_locals_valueArgAt_(m, locals, 0);

	if (ISSYMBOL(dir))
	{
		DATA(self)->driverCount = dbi_initialize(CSTRING(dir));
	}
	else
	{
		IoState_error_(IOSTATE, m, "argument 0 to method '%s' must be a Symbol, not a '%s'\n",
			CSTRING(IoMessage_name(m)), IoObject_name(dir));
	}

	if (DATA(self)->driverCount == -1)
	{
		IoState_error_(IOSTATE, m, "*** IoDBI error during dbi_initialize\n");
	}
	else
	{
		DATA(self)->didInit = 1;
	}

	return IONUMBER(DATA(self)->driverCount);
}
Exemplo n.º 9
0
IoDynLib *IoDynLib_callPluginInitFunc(IoDynLib *self, IoObject *locals, IoMessage *m)
{
	/*doc DynLib callPluginInit(functionName)
	Call's the dll function of the specified name. 
	Returns the result as a Number or raises an exception on error.
	*/
	
	intptr_t rc = 0;
	intptr_t *params = NULL;
	void *f = DynLib_pointerForSymbolName_(DATA(self),
									CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)));
	if (f == NULL)
	{
		IoState_error_(IOSTATE, m, "Error resolving call '%s'.",
					CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)));
		return IONIL(self);
	}

	if (IoMessage_argCount(m) < 1)
	{
		IoState_error_(IOSTATE, m, "Error, you must give an init function name to check for.");
		return IONIL(self);
	}

	params = io_calloc(1, sizeof(intptr_t) * 2);

	params[0] = (intptr_t)IOSTATE;
	params[1] = (intptr_t)IOSTATE->lobby;
	rc = ((intptr_t (*)(intptr_t, intptr_t))f)(params[0], params[1]);
	io_free(params);

	return IONUMBER(rc);
}
Exemplo n.º 10
0
Arquivo: IoSQLite.c Projeto: Akiyah/io
IoObject *IoSQLite_open(IoSQLite *self, IoObject *locals, IoMessage *m)
{
	/*doc SQLite open(optionalPathString)
	Opens the database.Returns self on success or nil upon failure.
	If the databse is locked, "yield" will be called until it is 
	accessable or timeoutSeconds has expired.
	*/

	char *zErrMsg;

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

	DATA(self)->db = sqlite_open(CSTRING(DATA(self)->path), 0, &zErrMsg);

	if (!DATA(self)->db)
	{
		IoSQLite_error_(self, zErrMsg);
	}
	else
	{
		IoSQLite_error_(self, "");
	}

	sqlite_busy_handler(DATA(self)->db, IoSQLite_busyHandler, self);
	sqlite_busy_timeout(DATA(self)->db, DATA(self)->timeoutSeconds*1000);
	return self;
}
Exemplo n.º 11
0
VALUE rb_digest(int argc, VALUE *argv, VALUE self) {
    VALUE string, options, method = Qnil;
    rb_scan_args(argc, argv, "11", &string, &options);

    if (TYPE(options) == T_HASH)
        method = rb_hash_aref(options, sMethod);

    int algo = NIL_P(method) ? 0 : FIX2INT(method);

    return SIZET2NUM(algo == 1 ? djhash(CSTRING(string)) : sdbm(CSTRING(string)));
}
Exemplo n.º 12
0
IO_METHOD(IoObject, setEnvironmentVariable)
{
	/*doc System setEnvironmentVariable(keyString, valueString)
	Sets the environment variable keyString to the value valueString.
*/

	// setenv() takes different args in different implementations
	IoSymbol *key = IoMessage_locals_symbolArgAt_(m, locals, 0);
	IoSymbol *value = IoMessage_locals_symbolArgAt_(m, locals, 1);
	setenv(CSTRING(key), CSTRING(value), 1);
	return self;
}
Exemplo n.º 13
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.º 14
0
VALUE db_postgres_adapter_initialize(VALUE self, VALUE options) {
    char *connection_info;
    VALUE db, user, pass, host, port, ssl;
    Adapter *a = db_postgres_adapter_handle(self);

    if (TYPE(options) != T_HASH)
        rb_raise(eSwiftArgumentError, "options needs to be a hash");

    db   = rb_hash_aref(options, ID2SYM(rb_intern("db")));
    user = rb_hash_aref(options, ID2SYM(rb_intern("user")));
    pass = rb_hash_aref(options, ID2SYM(rb_intern("password")));
    host = rb_hash_aref(options, ID2SYM(rb_intern("host")));
    port = rb_hash_aref(options, ID2SYM(rb_intern("port")));
    ssl  = rb_hash_aref(options, ID2SYM(rb_intern("ssl")));

    if (NIL_P(db))
        rb_raise(eSwiftConnectionError, "Invalid db name");
    if (NIL_P(host))
        host = rb_str_new2("127.0.0.1");
    if (NIL_P(port))
        port = rb_str_new2("5432");
    if (NIL_P(user))
        user = sUser;

    if (!NIL_P(ssl) && TYPE(ssl) != T_HASH)
            rb_raise(eSwiftArgumentError, "ssl options needs to be a hash");

    connection_info = (char *)malloc(4096);
    snprintf(connection_info, 4096, "dbname='%s' user='******' password='******' host='%s' port='%s'",
        CSTRING(db), CSTRING(user), CSTRING(pass), CSTRING(host), CSTRING(port));

    if (!NIL_P(ssl)) {
        append_ssl_option(connection_info, 4096, ssl, "sslmode",      "allow");
        append_ssl_option(connection_info, 4096, ssl, "sslcert",      0);
        append_ssl_option(connection_info, 4096, ssl, "sslkey",       0);
        append_ssl_option(connection_info, 4096, ssl, "sslrootcert",  0);
        append_ssl_option(connection_info, 4096, ssl, "sslcrl",       0);
    }

    a->connection = PQconnectdb(connection_info);
    free(connection_info);

    if (!a->connection)
        rb_raise(eSwiftRuntimeError, "unable to allocate database handle");
    if (PQstatus(a->connection) == CONNECTION_BAD)
        rb_raise(eSwiftConnectionError, PQerrorMessage(a->connection));

    PQsetNoticeProcessor(a->connection, (PQnoticeProcessor)db_postgres_adapter_notice, (void*)self);
    PQsetClientEncoding(a->connection, "utf8");
    return self;
}
Exemplo n.º 15
0
Arquivo: IoDate.c Projeto: bomma/io
IO_METHOD(IoDate, fromString)
{
	/*doc Date fromString(aString, formatString)
	Sets the receiver to the date specified by aString as parsed according to the given formatString. See the Date asString method for formatting rules. Returns self. 
	*/

	IoMessage_assertArgCount_receiver_(m, 2, self);
	{
		IoSymbol *date_input = IoMessage_locals_seqArgAt_(m, locals, 0);
		IoSymbol *format = IoMessage_locals_seqArgAt_(m, locals, 1);
		Date_fromString_format_(DATA(self), CSTRING(date_input), CSTRING(format));
	}
	IoObject_isDirty_(self, 1);
	return self;
}
Exemplo n.º 16
0
IoObject *IoCFFIPointer_castTo(IoCFFIPointer *self, IoObject *locals, IoMessage *m)
{
    IoObject *toType = IoMessage_locals_valueArgAt_(m, locals, 0);
    IoObject *o = IoState_on_doCString_withLabel_(IOSTATE, toType, "?typeString", "IoCFFIPointer_castTo");

    if(!ISNIL(o)) {
        char *typeStr = CSTRING(o);

        switch(typeStr[0]) {
            case '^':
                toType = IOCLONE(toType);
                *(DATA(toType)->valuePointer) = *((void **)IoCFFIDataType_ValuePointerFromObject_(toType, self));
                return toType;
            case '*':
                toType = IOCLONE(toType);
                IoCFFIDataType_rawSetValue(toType, self);
                return toType;
            default:
                IoState_error_(IOSTATE, m, "Wrong type to cast to.");
                break;
        }
    }
    else {
        // Mm... well, if the type to cast to does not have a typeString slot,
        // it should be an Io Object, so the address stored here is a pointer to an
        // Io Object. Simply cast the pointer and return it... dangerous but...
        
        IoObject *obj = (IoObject *)*(DATA(self)->valuePointer);
        if(ISOBJECT(obj))
            return (IoObject *)*(DATA(self)->valuePointer);
    }

    return IONIL(self);
}
Exemplo n.º 17
0
IO_METHOD(IoSeq, replaceMap)
{
	/*doc Sequence replaceMap(aMap)
	In the receiver, the keys of aMap replaced with its values. Returns self.
	*/

	IoMap *map = IoMessage_locals_mapArgAt_(m, locals, 0);
	UArray *ba = DATA(self);

	IO_ASSERT_NOT_SYMBOL(self);

	PHASH_FOREACH(IoMap_rawHash(map), k, v,
		{
		IoSymbol *subSeq = k;
		IoSymbol *otherSeq = v;

		if (ISSEQ(otherSeq))
		{
			UArray_replace_with_(ba, DATA(subSeq), DATA(otherSeq));
		}
		else
		{
			IoState_error_(IOSTATE, m,
							"argument 0 to method '%s' must be a Map with Sequence values, not '%s'",
							CSTRING(IoMessage_name(m)), IoObject_name(otherSeq));
		}
		}
	);
Exemplo n.º 18
0
Arquivo: IoCoroutine.c Projeto: jdp/io
void IoCoroutine_rawPrintBackTrace(IoCoroutine *self)
{
	IoObject *e = IoCoroutine_rawException(self);
	IoMessage *caughtMessage = IoObject_rawGetSlot_(e, IOSYMBOL("caughtMessage"));

	if (IoObject_rawGetSlot_(e, IOSYMBOL("showStack"))) // sanity check
	{
		IoState_on_doCString_withLabel_(IOSTATE, e, "showStack", "[Coroutine]");
	}
	else
	{
		IoSymbol *error = IoObject_rawGetSlot_(e, IOSYMBOL("error"));

		if (error)
		{
			fputs(CSTRING(error), stderr);
			fputs("\n", stderr);
		}
		else
		{
			fputs("error: [missing error slot in Exception object]\n", stderr);
		}

		if (caughtMessage)
		{
			UArray *ba = IoMessage_asMinimalStackEntryDescription(caughtMessage);
			fputs(UArray_asCString(ba), stderr);
			fputs("\n", stderr);
			UArray_free(ba);
		}
	}
}
Exemplo n.º 19
0
	IoValue *IoObject_catchException(IoObject *self, IoObject *locals, IoMessage *m)
	{
	  IoValue *result;
	  IoMessage_assertArgCount_(m, 3);
	  {
		 IoString *exceptionName = (IoString *)IoMessage_locals_stringArgAt_(m, locals, 0);
		 IoExceptionCatch *eCatch = IoState_pushExceptionCatchWithName_((IoState*)self->tag->state, 
		   CSTRING(exceptionName));

		 TInt r = 0;
		 TRAP(r, result = (IoValue*)IoMessage_locals_valueArgAt_(m, locals, 1);
				 IoState_popExceptionCatch_((IoState*)self->tag->state, eCatch););

		if(r != 0)
		{ 
		  IoObject_setSlot_to_((IoObject*)locals, USTRING("exceptionName"), eCatch->caughtName);
		  if (eCatch->caughtDescription)
		  { 
			IoObject_setSlot_to_(locals, USTRING("exceptionDescription"), 
			  eCatch->caughtDescription); 
		  }
		  else
		  { 
			IoObject_setSlot_to_(locals, USTRING("exceptionDescription"), 
			  USTRING("<no description>")); 
		  }      
		  IoState_popExceptionCatch_((IoState*)self->tag->state, eCatch);
		  result = (IoValue*)IoMessage_locals_valueArgAt_(m, locals, 2);
		}
	  }
Exemplo n.º 20
0
Arquivo: IoTagDB.c Projeto: Akiyah/io
Uint64Array *IoTagDB_tagArrayForTagNames_(IoTagDB *self, IoMessage *m, IoList *tagNames)
{
	TagDB *tdb = DATA(self);
	Uint64Array *tags = Uint64Array_new();
	int i;

	for (i = 0; i < IoList_rawSize(tagNames); i ++)
	{
		IoSeq *tagName = IoList_rawAt_(tagNames, i);
		symbolid_t keyid;
		
		IOASSERT(ISSEQ(tagName), "tag names must be Sequences");

		keyid = TagDB_idForSymbol_size_(tdb, CSTRING(tagName), IoSeq_rawSize(tagName));

		Uint64Array_append_(tags, keyid);
		/*
		{
		Datum *keyDatum = TagDB_symbolForId_(tdb, keyid);	
		printf("%s -> %i && ", CSTRING(tagName), (int)keyid);
		printf("%i -> %s\n", (int)keyid, (char *)(keyDatum->data));
		Datum_free(keyDatum);
		}
		*/
	}

	return tags;
}
Exemplo n.º 21
0
Arquivo: IoTagDB.c Projeto: Akiyah/io
IoObject *IoTagDB_atKeyPutTags(IoTagDB *self, IoObject *locals, IoMessage *m)
{
	/*doc TagDB atKeyPutTags(key, tagNameList)
	Sets the tags for key to those in tagNameList. Returns self.
	*/
	
	TagDB *tdb = DATA(self);
	IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoList *tagNames = IoMessage_locals_listArgAt_(m, locals, 1);
	symbolid_t keyid = TagDB_idForSymbol_size_(tdb, CSTRING(key), IoSeq_rawSize(key));
	
	// debugging check
	/*
	Datum *keyDatum = TagDB_symbolForId_(tdb, keyid);
	
	printf("%s -> %i\n", CSTRING(key), (int)keyid);
	printf("%i -> %s\n", (int)keyid, (char *)(keyDatum->data));
	assert(strcmp((char *)(keyDatum->data), (char *)CSTRING(key)) == 0);
	Datum_free(keyDatum);
	*/
	
	{
	Uint64Array *tags = IoTagDB_tagArrayForTagNames_(self, m, tagNames);
	TagDB_begin(tdb);
	TagDB_atKey_putTags_(tdb, keyid, tags);
	TagDB_commit(tdb);
	Uint64Array_free(tags);
	}
	return self;
}
Exemplo n.º 22
0
IO_METHOD(IoSandbox, doSandboxString)
{
	/*doc Sandbox doSandboxString(aString)
	Evaluate aString inside the Sandbox.
	*/

	IoState *boxState = IoSandbox_boxState(self);
	char *s = IoMessage_locals_cStringArgAt_(m, locals, 0);

	IoObject *result = IoState_doSandboxCString_(boxState, s);

	if (ISSYMBOL(result))
	{
		return IOSYMBOL(CSTRING(result));
	}

	if (ISSEQ(result))
	{
		return IOSEQ(IOSEQ_BYTES(result), IOSEQ_LENGTH(result));
	}

	if (ISNUMBER(result))
	{
		return IONUMBER(CNUMBER(result));
	}

	return IONIL(self);
}
Exemplo n.º 23
0
IO_METHOD(IoDirectory, create)
{
    /*doc Directory create
    Create the directory if it doesn't exist.
    Returns self on success (or if the directory already exists), nil on failure.
    */

    if (!opendir(CSTRING(DATA(self)->path)))
    {
        // not there, so make it
        int r = MKDIR(CSTRING(DATA(self)->path), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
        return (r == 0) ? self : IONIL(self);
    }

    return self;
}
Exemplo n.º 24
0
Arquivo: IoFont.c Projeto: Teslos/io
IoObject *IoFont_drawString(IoFont *self, IoObject *locals, IoMessage *m)
{
	/*doc Font drawString(aString, optionalStartIndex, optionalEndIndex)
	Draws aString using the optional start and end indexes, if supplied. Returns self.
<p>
Note; Fonts are drawn as RGBA pixel maps. These blending options are recommended:
<pre>	
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
</pre>	
	*/

	IoSymbol *textString = IoMessage_locals_seqArgAt_(m, locals, 0);
	int startIndex = 0;
	int endIndex;

	if (IoMessage_argCount(m) > 1)
	{
		startIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 1));
		if (startIndex > (int)IoSeq_rawSize(textString)) startIndex = (int)IoSeq_rawSize(textString);
	}

	if (IoMessage_argCount(m) > 2)
	{
		endIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 2));
	}
	else
	{
		endIndex = IoSeq_rawSize(textString);
	}

	GLFont_drawString(DATA(self)->font, CSTRING(textString) , startIndex, endIndex);
	IoFont_checkError(self, locals, m);
	return self;
}
Exemplo n.º 25
0
Arquivo: IoFont.c Projeto: Teslos/io
IoObject *IoFont_lengthOfString(IoFont *self, IoObject *locals, IoMessage *m)
{
	/*doc Font widthOfString(aString)
	Returns a Number with the width that aString would render 
	to with the receiver's current settings.
	*/

	IoSymbol *text = IoMessage_locals_seqArgAt_(m, locals, 0);
	int startIndex = 0;
	int max = IoSeq_rawSize(text);
	int endIndex = max;

	if (IoMessage_argCount(m) == 2)
	{
		startIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 1));
		if (startIndex > max) startIndex = max;
	}

	if (IoMessage_argCount(m) > 2)
	{
		endIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 2));
		if (startIndex > max) endIndex = max;
	}

	return IONUMBER( GLFont_lengthOfString( DATA(self)->font, CSTRING(text), startIndex, endIndex) );
}
Exemplo n.º 26
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.º 27
0
Arquivo: IoAVCodec.c Projeto: BMeph/io
int IoAVCodec_openFile(IoAVCodec *self)
{
	//AVInputFormat *inputFormat;
	IoObject *fileName = IoObject_symbolGetSlot_(self, IOSYMBOL("path"));
	int err = av_open_input_file(&DATA(self)->formatContext, CSTRING(fileName), NULL, 0, NULL);
	return err;
}
Exemplo n.º 28
0
Arquivo: IoAVCodec.c Projeto: BMeph/io
IoObject *IoAVCodec_open(IoAVCodec *self, IoObject *locals, IoMessage *m)
{
	/*doc AVCodec open
	Opens the input file. Return self on success or raises an exception on error.
	*/
	
	int err;

	IoAVCodec_registerIfNeeded(self);
	IoAVCodec_freeContextIfNeeded(self);
	IoAVCodec_createContextIfNeeded(self);

	DATA(self)->isAtEnd = 0;

	err = IoAVCodec_openFile(self);

	if (err != 0)
	{
		IoObject *fileName = IoObject_symbolGetSlot_(self, IOSYMBOL("path"));
		IoState_error_(IOSTATE, m, "error %i opening file %s\n", err, CSTRING(fileName));
		return IONIL(self);
	}

	IoAVCodec_findStreams(self);
	av_read_play(DATA(self)->formatContext);

	return self;
}
Exemplo n.º 29
0
VALUE db_postgres_statement_initialize(VALUE self, VALUE adapter, VALUE sql) {
    PGresult *result;
    Statement *s = db_postgres_statement_handle(self);
    Adapter *a   = db_postgres_adapter_handle_safe(adapter);

    snprintf(s->id, 128, "s%s", CSTRING(rb_uuid_string()));
    s->adapter = adapter;

    if (!a->native)
        sql = db_postgres_normalized_sql(sql);

    result = PQprepare(a->connection, s->id, CSTRING(sql), 0, 0);
    db_postgres_check_result(result);
    PQclear(result);
    return self;
}
Exemplo n.º 30
0
//doc ClutterColor fromString(str)
IO_METHOD(IoClutterColor, fromString) {
  ClutterColor color;
  char *seq = CSTRING(IoMessage_locals_seqArgAt_(m, locals, 0));
  clutter_color_from_string(&color, seq);

  return IoClutterColor_newWithColor(IOSTATE, color);
}