Example #1
0
/**
	sys_env : void -> #list
	<doc>Return all the (key,value) pairs in the environment as a chained list</doc>
**/
static value sys_env() {
   value result = alloc_array(0);
   #ifndef HX_WINRT
	char **e = environ;
	while( *e ) {
		char *x = strchr(*e,'=');
		if( x == NULL ) {
			e++;
			continue;
		}
                val_array_push(result,alloc_string_len(*e,(int)(x-*e)));
                val_array_push(result,alloc_string(x+1));
		e++;
	}
   #endif
	return result;
}
Example #2
0
value wx_file_dialog_show(value ioData)
{
   wxWindow *parent = 0;
   wxString message;
   wxString directory;
   wxString file;
   wxString filter;
   int      style;
   wxPoint  position;
   wxSize   size;

   ValueToWX(val_field(ioData,val_id("parent")),parent);
   ValueToWX(val_field(ioData,val_id("message")),message);
   ValueToWX(val_field(ioData,val_id("directory")),directory);
   ValueToWX(val_field(ioData,val_id("file")),file);
   ValueToWX(val_field(ioData,val_id("filter")),filter);
   ValueToWX(val_field(ioData,val_id("style")),style);
   ValueToWX(val_field(ioData,val_id("size")),size);

   wxFileDialog *dlg = new wxFileDialog(parent,message,directory,file,filter,style,position,size);
   bool result = dlg->ShowModal()==wxID_OK;

   if (result)
   {
     alloc_field(ioData,val_id("file"), WXToValue(dlg->GetFilename()));
     alloc_field(ioData,val_id("directory"), WXToValue(dlg->GetDirectory()));
     wxArrayString files;
     dlg->GetFilenames(files);
     value array = val_field(ioData,val_id("files"));
     for(int i=0;i<files.size();i++)
        val_array_push(array,WXToValue(files[i]));
   }

   dlg->Destroy();
   return alloc_bool(result);
}
Example #3
0
/**
	sys_read_dir : string -> string list
	<doc>Return the content of a directory</doc>
**/
static value sys_read_dir( value p) {
	val_check(p,string);

        value result = alloc_array(0);
#ifdef HX_WINRT
   auto folder = (Windows::Storage::StorageFolder::GetFolderFromPathAsync( ref new Platform::String(val_wstring(p)) ))->GetResults();
   auto results = folder->GetFilesAsync(Windows::Storage::Search::CommonFileQuery::DefaultQuery)->GetResults();
   for(int i=0;i<results->Size;i++)
      val_array_push(result,alloc_wstring(results->GetAt(i)->Path->Data()));

#elif defined(NEKO_WINDOWS)
	const wchar_t *path = val_wstring(p);
	size_t len = wcslen(path);
   if (len>MAX_PATH)
      return alloc_null();

	WIN32_FIND_DATAW d;
	HANDLE handle;
	buffer b;
   wchar_t searchPath[ MAX_PATH + 4 ];
   memcpy(searchPath,path, len*sizeof(wchar_t));


	if( len && path[len-1] != '/' && path[len-1] != '\\' )
      searchPath[len++] = '/';
   searchPath[len++] = '*';
   searchPath[len++] = '.';
   searchPath[len++] = '*';
   searchPath[len] = '\0';

	gc_enter_blocking();
	handle = FindFirstFileW(searchPath,&d);
	if( handle == INVALID_HANDLE_VALUE )
	{
		gc_exit_blocking();
		return alloc_null();
	}
	while( true ) {
		// skip magic dirs
		if( d.cFileName[0] != '.' || (d.cFileName[1] != 0 && (d.cFileName[1] != '.' || d.cFileName[2] != 0)) ) {
		   gc_exit_blocking();
			val_array_push(result,alloc_wstring(d.cFileName));
			gc_enter_blocking();
		}
		if( !FindNextFileW(handle,&d) )
			break;
	}
	FindClose(handle);
	gc_exit_blocking();
#elif !defined(EPPC)
	DIR *d;
	struct dirent *e;
   const char *name = val_string(p);
	gc_enter_blocking();
	d = opendir(name);
	if( d == NULL )
	{
		gc_exit_blocking();
      val_throw(alloc_string("Invalid directory"));
	}
	while( true ) {
		e = readdir(d);
		if( e == NULL )
			break;
		// skip magic dirs
		if( e->d_name[0] == '.' && (e->d_name[1] == 0 || (e->d_name[1] == '.' && e->d_name[2] == 0)) )
			continue;
		gc_exit_blocking();
		val_array_push(result, alloc_string(e->d_name) );
		gc_enter_blocking();
	}
	closedir(d);
#endif
	gc_exit_blocking();
	return result;
}