コード例 #1
0
ファイル: lich.c プロジェクト: mtmiron/lich
int main(int argc, char **argv)
{
#ifndef __MINGW32__
	FILE *fileconf;
#endif
	char *tmp;
	char lichdir[256] = { '\0' };
	char datadir[512] = { '\0' };
	int nerr;

	sig_setup();

#ifndef __MINGW32__
	snprintf(lichdir, 256, "%s%s", getenv("HOME"), "/.lich.cfg");
	fileconf = fopen(lichdir, "rb");
	if (!fileconf) {
		perror("fopen");
		fprintf(stderr, "Your `$HOME/.lich.cfg' file cannot be opened: please create the file and put the full directory name Lich should use for settings/config files in it.\n\nFor example, to do that, you could type:    echo \"$HOME/lich\" > $HOME/.lich.cfg\n");
		exit(EXIT_FAILURE);
	}
	fgets(lichdir, 256, fileconf);
	fclose(fileconf);
	lichdir[strnlen(lichdir, 256) - 1] = '/';
	chdir(lichdir);
#else
	NtInitialize(&argc, &argv);
	strncpy(lichdir, argv[0], 255);
	tmp = &lichdir[strlen(lichdir)];
	while (tmp && (*tmp != '\\') && (*tmp != '/')) {
		tmp--;
	}
	*tmp = '\0';
	chdir(lichdir);
#endif
	
	init_ruby_interpreter(argc, argv);
	init_libs();
	prep_ruby_env();

	getcwd(lichdir, 255);
	lichdir[strlen(lichdir) + 1] = '\0';
	lichdir[strlen(lichdir)] = RSTRING(rb_const_get(rb_cFile, rb_intern("SEPARATOR")))->ptr[0];

	strcpy(datadir, lichdir);
	strcat(datadir, "data");
	datadir[strlen(datadir)] = lichdir[strlen(lichdir) - 1];

	rb_gv_set("$data_dir", rb_str_new(datadir, strlen(datadir)));
	rb_gv_set("$lich_dir", rb_str_new(lichdir, strlen(lichdir)));

	ruby_safe_level = 0;
	if (nerr = ruby_exec()) {
		tmp = RSTRING(rb_funcall(rb_gv_get("$!"), rb_intern("to_s"), 0))->ptr;
		if (!strncasecmp(tmp, "exit", 4)) ruby_stop(0);
		fprintf(stderr, "%s\n", tmp);
		fprintf(stderr, "%s\n", RSTRING(rb_funcall(rb_funcall(rb_gv_get("$!"), rb_intern("backtrace"), 0), rb_intern("join"), 1, rb_str_new2("\n")))->ptr);
		ruby_stop(nerr);
	}
	ruby_stop(0);
}
コード例 #2
0
ファイル: main.c プロジェクト: weimingtom/eriri_lua
int main(int argc, char *argv[])
{
	int ret;
	const char *script = argv[1];

	if (script == NULL) {
		script = 
			//"alphadraw.rb";
			"alpha.rb";
			//"aadraw.rb";
			//"test_fib.rb";
	}

	ruby_debug = Qtrue;
	ruby_verbose = Qtrue;

	ruby_init();
	ruby_init_loadpath();
	ruby_script(script);
	rb_load_file(script);
	ret = ruby_cleanup(ruby_exec());

	//exit(ret);
	return(ret);
}
コード例 #3
0
ファイル: rpmruby.c プロジェクト: hahnakane/junkcode
rpmRC rpmrubyRunFile(rpmruby ruby, const char * fn, const char ** resultp)
{
    rpmRC rc = RPMRC_FAIL;

RUBYDBG((stderr, "--> %s(%p,%s,%p)\n", __FUNCTION__, ruby, fn, resultp));

    if (ruby == NULL) ruby = rpmrubyI();

    if (fn == NULL)
	goto exit;

#if defined(WITH_RUBYEMBED)
#if !defined(HAVE_RUBY_DEFINES_H)	/* XXX ruby-1.8.6 */
    rb_load_file(fn);
    ruby->state = ruby_exec();
#else
    ruby->state = ruby_exec_node(rb_load_file(fn));
#endif
    if (resultp != NULL)
	*resultp = RSTRING_PTR(rb_gv_get("$result"));
    rc = RPMRC_OK;
#endif	/* WITH_RUBYEMBED */

exit:
RUBYDBG((stderr, "<-- %s(%p,%s,%p) rc %d\n", __FUNCTION__, ruby, fn, resultp, rc));
    return rc;
}
コード例 #4
0
ファイル: ruby.c プロジェクト: 0xroot/radare2
static int slurp_ruby(const char *file)
{
	if (r_file_exists(file)) {
		rb_load_file(file);
		ruby_exec();
		return R_TRUE;
	}
	eprintf("lang_ruby: Cannot open '%s'\n", file);
	return R_FALSE;
}
コード例 #5
0
	Module* RubyModule::CreateModule(std::string& path)
	{
		path = UTF8ToSystem(path);
		rb_load_file(path.c_str());
		ruby_exec();
		// TODO: Do we need to call ruby_cleanup() here?

		Poco::Path p(path);
		std::string basename = p.getBaseName();
		std::string name = basename.substr(0,basename.length()-ruby_suffix.length()+3);
		std::string moduledir = path.substr(0,path.length()-basename.length()-3);

		return new RubyModuleInstance(host, path, moduledir, name);
	}
コード例 #6
0
ファイル: ruby_module.cpp プロジェクト: mital/kroll
	Module* RubyModule::CreateModule(std::string& path)
	{
		rb_load_file(path.c_str());
		ruby_exec();

//		ruby_cleanup();  <-- at some point we need to call?


		Poco::Path p(path);
		std::string basename = p.getBaseName();
		std::string name = basename.substr(0,basename.length()-ruby_suffix.length()+3);
		std::string moduledir = path.substr(0,path.length()-basename.length()-3);

		Logger *logger = Logger::Get("Ruby");
		logger->Info("Loading Ruby path=%s", path.c_str());

		return new RubyModuleInstance(host, path, moduledir, name);
	}
コード例 #7
0
Kross::Api::Object::Ptr RubyScript::execute()
{
#ifdef KROSS_RUBY_SCRIPT_DEBUG
    krossdebug("RubyScript::execute()");
#endif
    if(d->m_compile == 0)
    {
        compile();
    }
#ifdef KROSS_RUBY_SCRIPT_DEBUG
    krossdebug("Start execution");
#endif
    selectScript();
    int result = ruby_exec();
    if (result != 0)
    {
#ifdef KROSS_RUBY_SCRIPT_DEBUG
        krossdebug("Execution has failed");
#endif
        if( TYPE( ruby_errinfo )  == T_DATA && RubyExtension::isOfExceptionType( ruby_errinfo ) )
        {
#ifdef KROSS_RUBY_SCRIPT_DEBUG
            krossdebug("Kross exception");
#endif
            setException( RubyExtension::convertToException( ruby_errinfo ) );
        } else {
            setException( new Kross::Api::Exception(QString("Failed to execute ruby code: %1").arg(STR2CSTR( rb_obj_as_string(ruby_errinfo) )), 0) ); // TODO: get the error
        }
    }

    unselectScript();
#ifdef KROSS_RUBY_SCRIPT_DEBUG
    krossdebug("Execution is finished");
#endif
    return 0;
}
コード例 #8
0
/**
 * Load a Ruby file then run the function corresponding to the service by
 * passing the conf, inputs and outputs parameters by refernce as Ruby Hash.
 *
 * @param main_conf the conf maps containing the main.cfg settings
 * @param request the map containing the HTTP request
 * @param s the service structure
 * @param real_inputs the maps containing the inputs
 * @param real_outputs the maps containing the outputs
 * @return SERVICE_SUCCEEDED or SERVICE_FAILED if the service run, -1 
 *  if the service failed to load or throw error at runtime.
 */
int zoo_ruby_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
#if RUBY_API_VERSION_MAJOR >= 2 || RUBY_API_VERSION_MINOR == 9
  ruby_sysinit(&argc,&argv);
  RUBY_INIT_STACK;
#endif
  ruby_init();
  maps* m=*main_conf;
  maps* inputs=*real_inputs;
  maps* outputs=*real_outputs;
  map* tmp0=getMapFromMaps(*main_conf,"lenv","cwd");
  char *ntmp=tmp0->value;
  map* tmp=NULL;
  ruby_init_loadpath();
  ruby_script("ZOO_EMBEDDED_ENV");
  
  VALUE klass=rb_define_module("Zoo");
  rb_define_const(klass,"SERVICE_SUCCEEDED",INT2FIX(3));
  rb_define_const(klass,"SERVICE_FAILED",INT2FIX(4));
  typedef VALUE (*HOOK)(...);
  rb_define_module_function(klass,"Translate",reinterpret_cast<HOOK>(RubyTranslate),-1);
  rb_define_module_function(klass,"UpdateStatus",reinterpret_cast<HOOK>(RubyUpdateStatus),-1);

  int error = 0;
		
  ID rFunc=Qnil;
  tmp=getMap(s->content,"serviceProvider");
  if(tmp!=NULL){
#if RUBY_VERSION_MINOR == 8
    const char* script = ruby_sourcefile = rb_source_filename(tmp->value);
    rb_protect(LoadWrap, reinterpret_cast<VALUE>(script), &error);
#else
    rb_load_protect(rb_str_new2(tmp->value), 0, &error);
#endif
    if(error) {
      ruby_trace_error(m);
      return -1;
    }
#if RUBY_VERSION_MINOR == 8
    ruby_exec();
#else
    ruby_exec_node(NULL);
#endif
  }
  else{
    map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file.");
    addToMap(err,"code","NoApplicableCode");
    printExceptionReportResponse(m,err);
    return -1;
  }
  int res=SERVICE_FAILED;
  rFunc=rb_intern(s->name);
  if(rFunc!=Qnil){
    VALUE arg1=RubyHash_FromMaps(m);
    VALUE arg2=RubyHash_FromMaps(inputs);
    VALUE arg3=RubyHash_FromMaps(outputs);
    VALUE rArgs[3]={arg1,arg2,arg3};
    if (!rArgs)
      return -1;
    struct my_callback data;
    data.obj=Qnil;
    data.method_id=rFunc;
    data.nargs=3;
    data.args[0]=rArgs[0];
    data.args[1]=rArgs[1];
    data.args[2]=rArgs[2];
    typedef VALUE (*HOOK)(VALUE);
    VALUE tres=rb_protect(reinterpret_cast<HOOK>(FunCallWrap),(VALUE)(&data),&error);
    if (TYPE(tres) == T_FIXNUM) {
      res=FIX2INT(tres);
      freeMaps(real_outputs);
      free(*real_outputs);
      freeMaps(main_conf);
      free(*main_conf);
      *main_conf=mapsFromRubyHash(arg1);
      *real_outputs=mapsFromRubyHash(arg3);
#ifdef DEBUG
      dumpMaps(*main_conf);
      dumpMaps(*real_outputs);
#endif
    }else{
      ruby_trace_error(m);
      res=-1;
    }
  }
  else{
    char tmpS[1024];
    sprintf(tmpS, "Cannot find the %s function in the %s file.\n", s->name, tmp->value);
    map* tmps=createMap("text",tmpS);
    printExceptionReportResponse(m,tmps);
    res=-1;
  }
  ruby_finalize();
  return res;
}