Example #1
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);
	}
}
Example #2
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);
}
Example #3
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;
}
Example #4
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 existance of that path instead. 
	*/

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

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

	dirp = opendir(CSTRING(path));

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

	(void)closedir(dirp);
	return IOTRUE(self);
}
Example #5
0
File: IoFile.c Project: achoy/io
IO_METHOD(IoFile, moveTo_)
{
	/*doc File moveTo(pathString)
	Moves the file specified by the receiver's path to the
	new path pathString. Raises a File doesNotExist exception if the
	file does not exist or a File nameConflict exception if the file
	nameString already exists.
	*/

	IoSymbol *newPath = IoMessage_locals_symbolArgAt_(m, locals, 0);
	const char *fromPath = UTF8CSTRING(DATA(self)->path);
	const char *toPath = UTF8CSTRING(newPath);

	if(strcmp(fromPath, toPath) != 0)
	{
		int error;

		remove(toPath); // to make sure we do not get an error
		error = rename(fromPath, toPath);

		if (error)
		{
			IoState_error_(IOSTATE, m, "error moving file '%s' to '%s'", fromPath, toPath);
		}
	}

	return self;
}
Example #6
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
}
Example #7
0
IO_METHOD(IoDuration, asString)
{
/*doc Duration asString(formatString)
Returns a string representation of the receiver. The formatString argument is optional. If present, the returned string will be formatted according to ANSI C date formating rules.
<p>
<pre>	
%y years without century as two-digit decimal number (00-99)
%Y year with century as four-digit decimal number

%d days
%H hour as two-digit 24-hour clock decimal integer (00-23)
%M minute as a two-digit decimal integer (00-59)
%S second as a two-digit decimal integer (00-59)

The default format is "%Y %d %H:%M:%S".
</pre>
*/
	UArray *ba;
	char *format = NULL;

	if (IoMessage_argCount(m) == 1)
	{
		format = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0));
	}

	ba = Duration_asUArrayWithFormat_(DATA(self), format);
	return IoState_symbolWithUArray_copy_convertToFixedWidth(IOSTATE, ba, 0);
}
Example #8
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);
}
Example #9
0
File: IoRegex.c Project: ADTSH/io
IoObject *IoRegex_with(IoRegex *self, IoObject *locals, IoMessage *m)
{
	/*doc Regex with(pattern)
	Returns a new Regex created from the given pattern string.
	*/
	
	return IoRegex_newWithPattern_(IOSTATE, IoMessage_locals_symbolArgAt_(m, locals, 0));
}
Example #10
0
IoObject *IoCairoSVGSurface_create(IoCairoSVGSurface *self, IoObject *locals, IoMessage *m)
{
	char *filename = CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0));
	double w = IoMessage_locals_doubleArgAt_(m, locals, 1);
	double h = IoMessage_locals_doubleArgAt_(m, locals, 2);

	return IoCairoSurface_newWithRawSurface_(IOSTATE, m, cairo_svg_surface_create(filename, w, h));
}
Example #11
0
IO_METHOD(IoMessage, protoSetName)
{
	/*doc Message setName(aString)
	Sets the name of the receiver. Returns self. 
	*/
	IoMessage_rawSetName_(self, IoMessage_locals_symbolArgAt_(m, locals, 0));
	//IoMessage_cacheIfPossible(self);
	return self;
}
Example #12
0
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;
}
Example #13
0
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;
}
Example #14
0
IO_METHOD(IoMessage, setLabel)
{
	/*doc Message setLabel(aString)
	Sets the label of the message and its children. Returns self.
	*/

	IoMessage_label_(self, IoMessage_locals_symbolArgAt_(m , locals, 0));
	return self;
}
Example #15
0
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;
}
Example #16
0
File: IoFile.c Project: 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;
}
Example #17
0
IoDynLib *IoDynLib_setPath(IoDynLib *self, IoObject *locals, IoMessage *m)
{
	/*doc DynLib setPath(aString)
	Sets the path to the dynamic library. Returns self.
	*/

	DynLib_setPath_(DATA(self),
					CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)));
	return self;
}
Example #18
0
IoDynLib *IoDynLib_setInitFuncName(IoDynLib *self, IoObject *locals, IoMessage *m)
{
	/*doc DynLib setInitFuncName(aString)
	Sets the initialization function name for the dynamic library. Returns self.
	*/

	DynLib_setInitFuncName_(DATA(self),
						CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)));
	return self;
}
Example #19
0
IoDynLib *IoDynLib_setFreeFuncName(IoDynLib *self, IoObject *locals, IoMessage *m)
{
	/*doc DynLib setFreeFuncName(aString)
	Sets the io_free function name. Returns self.
	*/

	DynLib_setFreeFuncName_(DATA(self),
						CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)));
	return self;
}
Example #20
0
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;
}
Example #21
0
IoObject *IoSQLite3_columnNamesOfTable(IoSQLite3 *self, IoObject *locals, IoMessage *m)
{
	/*doc SQLite3 columnNamesOfTable(tableName)
	Returns a list containing the names of all columns in the specified table.
	*/

	IoSymbol *tableName = IoMessage_locals_symbolArgAt_(m, locals, 0);
	IoSymbol *s = IoSeq_newSymbolWithFormat_(IOSTATE, "PRAGMA TABLE_INFO(%s)", CSTRING(tableName));
	return IoSQLite3_execWithCallback(self, locals, m, s, IoSQLite3_columnNamesResultRow);
}
Example #22
0
IoObject *IoImage_setPath(IoImage *self, IoObject *locals, IoMessage *m)
{
	/*doc Image setPath(aString)
	Sets the image path. Returns self.
	*/

	IoSymbol *s = IoMessage_locals_symbolArgAt_(m, locals, 0);
	Image_path_(DATA(self)->image, CSTRING(s));
	return self;
}
Example #23
0
File: IoDate.c Project: 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);
	}
}
Example #24
0
IoObject *IoEditLine_readLine(IoEditLine *self, IoObject *locals, IoMessage *m)
{
	int count = 0;
	const char *line = NULL;

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

	line = el_gets(DATA(self)->editline, &count);

	if (line && count >= 0)
		return IOSEQ(line, (size_t)count);
	else
		return IONIL(self);
}
Example #25
0
IO_METHOD(IoObject, messageForString)
{
	/*doc Compiler messageForString(aString, optionalLabelString)
	Returns the compiled message object for aString.
	*/

	IoSymbol *string = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoSymbol *label  = IoMessage_rawLabel(m);

	if (IoMessage_argCount(m) > 1)
	{
		label = IoMessage_locals_symbolArgAt_(m, locals, 1);
	}

	return IoMessage_newFromText_labelSymbol_(IOSTATE, CSTRING((IoSymbol *)string), (IoSymbol *)label);
}
Example #26
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;
}
Example #27
0
IO_METHOD(IoDirectory, setCurrentWorkingDirectory)
{
    /*doc Directory setCurrentWorkingDirectory(pathString)
    Sets the current working directory path.
    Returns true on success or false on error.
    */

    IoSymbol *path = IoMessage_locals_symbolArgAt_(m, locals, 0);

    if(chdir(CSTRING(path)) == -1)
    {
        return IOFAILURE(self);
    }

    return IOSUCCESS(self);
}
Example #28
0
IO_METHOD(IoObject, getEnvironmentVariable)
{
	/*doc System getEnvironmentVariable(nameString)
	Returns a string with the value of the environment
	variable whose name is specified by nameString.
	*/

	IoSymbol *key = IoMessage_locals_symbolArgAt_(m, locals, 0);
	char *s = getenv(CSTRING(key));

	if (!s)
	{
		return ((IoState *)IOSTATE)->ioNil;
	}

	return IoState_symbolWithCString_(IOSTATE, s);
}
Example #29
0
File: IoSystem.c Project: jdp/io
IO_METHOD(IoObject, system)
{
	/*doc System system(aString)
	Makes a system call and returns a Number for the return value.
	*/

	IoSymbol *s = IoMessage_locals_symbolArgAt_(m, locals, 0);
	
	char *buf = NULL;
	buf = (char *)getcwd(buf, 1024);
	
	//printf("CURDIR: [%s]\n", buf);
	//printf("SYSTEM: [%s]\n", CSTRING(s));
	int result = system(CSTRING(s))/ 256;
	//printf("system result = %i\n", result);
	return IONUMBER(result);
}
Example #30
0
IoObject *IoImage_save(IoImage *self, IoObject *locals, IoMessage *m)
{
	/*doc Image save(optionalPathString)
	Sets the path to optionalPathString if provided and saves the image 
	in the format specified by the path extension. Returns self on success, nil on failure.
	*/

	if (IoMessage_argCount(m) > 0)
	{
		IoSymbol *path = IoMessage_locals_symbolArgAt_(m, locals, 0);
		Image_path_(DATA(self)->image, CSTRING(path));
	}

	Image_save(DATA(self)->image);
	IoImage_checkError(self, locals, m);
	return self;
}