Beispiel #1
0
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);
}
Beispiel #2
0
int main(int argc, char **argv)
{
#ifdef _WIN32
    NtInitialize(&argc, &argv);
#endif
    init();
    proc_args(argc, argv);
    run();
    return 0;
}
Beispiel #3
0
static int ensure_ruby_initialized(void)
{
    if (!ruby_initialized)
    {
#ifdef DYNAMIC_RUBY
	if (ruby_enabled(TRUE))
	{
#endif
#ifdef _WIN32
	    /* suggested by Ariya Mizutani */
	    int argc = 1;
	    char *argv[] = {"gvim.exe"};
	    char **argvp = argv;
	    NtInitialize(&argc, &argvp);
#endif
	    {
#if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK)
		ruby_init_stack(ruby_stack_start);
#endif
		ruby_init();
	    }
#ifdef RUBY19_OR_LATER
	    {
		int dummy_argc = 2;
		char *dummy_argv[] = {"vim-ruby", "-e0"};
		ruby_options(dummy_argc, dummy_argv);
	    }
	    ruby_script("vim-ruby");
#else
	    ruby_init_loadpath();
#endif
	    ruby_io_init();
	    ruby_vim_init();
	    ruby_initialized = 1;
#ifdef DYNAMIC_RUBY
	}
	else
	{
	    EMSG(_("E266: Sorry, this command is disabled, the Ruby library could not be loaded."));
	    return 0;
	}
#endif
    }
    return ruby_initialized;
}
Beispiel #4
0
int
main(int argc, char **argv, char **envp)
{
#ifdef RUBY_GC_STRESS
    RUBY_EXTERN int gc_stress;
    gc_stress = getenv("RUBY_GC_STRESS") != NULL;
#endif
#ifdef _WIN32
    NtInitialize(&argc, &argv);
#endif
#if defined(__MACOS__) && defined(__MWERKS__)
    argc = ccommand(&argv);
#endif

    {
	RUBY_INIT_STACK;
	ruby_init();
	ruby_options(argc, argv);
	ruby_run();
    }
    return 0;
}
Beispiel #5
0
int main( int argc, char** argv ) 
{
  int state  = 0;
  int rc     = 0;
  int opt_mv = 0;

  crate_app ca;

  /** startup items from ruby's original main.c */
#ifdef _WIN32
  NtInitialize(&argc, &argv);
#endif
#if defined(__MACOS__) && defined(__MWERKS__)
  argc = ccommand(&argv);
#endif

  /* setup ruby */
  ruby_init();
  ruby_script( argv[0] );
  ruby_init_loadpath();

  /* strip out the crate specific arguments from argv using --crate- */
  opt_mv = crate_init_from_options( &ca, argc, argv );
  argc -= opt_mv;
  argv += opt_mv;
 
  /* printf("crate file  : %s\n", ca.file_name);   */
  /* printf("crate class : %s\n", ca.class_name);  */
  /* printf("crate method: %s\n", ca.method_name); */

  /* make ARGV available */
  ruby_set_argv( argc, argv );

  /* initialize all extensions */
  Init_ext();

  /* load up the amalgalite libs */
  am_bootstrap_lift( cARB, Qnil );
 
  /* remove the current LOAD_PATH */
  rb_ary_clear( rb_gv_get( "$LOAD_PATH" ) );

  /* invoke the class / method passing in ARGV and ENV */
  rb_protect( crate_wrap_app, (VALUE)&ca, &state );

  /* check the results */
  if ( state ) {

    /* exception was raised, check the $! var */
    VALUE lasterr  = rb_gv_get("$!");
   
    /* system exit was called so just propogate that up to our exit */
    if ( rb_obj_is_instance_of( lasterr, rb_eSystemExit ) ) {

      rc = NUM2INT( rb_attr_get( lasterr, rb_intern("status") ) );
      /*printf(" Caught SystemExit -> $? will be %d\n", rc ); */

    } else {

      /* some other exception was raised so dump that out */
      VALUE klass     = rb_class_path( CLASS_OF( lasterr ) );
      VALUE message   = rb_obj_as_string( lasterr );
      VALUE backtrace = rb_funcall( lasterr, rb_intern("backtrace"), 0 );

      fprintf( stderr, "%s: %s\n", RSTRING( klass )->ptr, RSTRING( message )->ptr );
      rb_iterate( rb_each, backtrace, dump_backtrace, Qnil );

      rc = state;
    }
  } 

  free( ca.file_name );
  free( ca.class_name );
  free( ca.method_name );

  /* shut down ruby */
  ruby_finalize();

  /* exit the program */
  exit( rc );
}