Exemplo n.º 1
0
static void
require_libraries(VALUE *req_list)
{
    VALUE list = *req_list;
    VALUE self = rb_vm_top_self();
    ID require;
    rb_thread_t *th = GET_THREAD();
    rb_block_t *prev_base_block = th->base_block;
    rb_encoding *extenc = rb_default_external_encoding();
    int prev_parse_in_eval = th->parse_in_eval;
    th->base_block = 0;
    th->parse_in_eval = 0;

    Init_ext();		/* should be called here for some reason :-( */
    CONST_ID(require, "require");
    while (list && RARRAY_LEN(list) > 0) {
	VALUE feature = rb_ary_shift(list);
	rb_enc_associate(feature, extenc);
	RBASIC(feature)->klass = rb_cString;
	OBJ_FREEZE(feature);
	rb_funcall2(self, require, 1, &feature);
    }
    *req_list = 0;

    th->parse_in_eval = prev_parse_in_eval;
    th->base_block = prev_base_block;
}
Exemplo n.º 2
0
Arquivo: encoding.c Projeto: 217/ruby
static int
enc_set_filesystem_encoding(void)
{
    int idx;
#if defined NO_LOCALE_CHARMAP
    idx = rb_enc_to_index(rb_default_external_encoding());
#elif defined _WIN32 || defined __CYGWIN__
    char cp[sizeof(int) * 8 / 3 + 4];
    snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
    idx = rb_enc_find_index(cp);
    if (idx < 0) idx = rb_ascii8bit_encindex();
#else
    idx = rb_enc_to_index(rb_default_external_encoding());
#endif

    enc_alias_internal("filesystem", idx);
    return idx;
}
Exemplo n.º 3
0
void CRScriptCore::InitializeEnvironment()
{
	ATLTRACE(_("Initialize Environment in Thread:%08X\n"), GetCurrentThreadId());
#ifndef __IRubyEngine_INTERFACE_DEFINED__
	int stacktop;
	s_pStackTop = reinterpret_cast<LPBYTE>(&stacktop);
#endif
        int dummyargc(1);
        char* dummyargv[] = {"dummy", NULL };
        char** pargv;
	ruby_sysinit(&dummyargc, &pargv);
	RUBY_INIT_STACK;
	ruby_init();
	ruby_options(3, asr_argv);
        s_pEncoding = rb_default_internal_encoding();
        if (!s_pEncoding) s_pEncoding = rb_default_external_encoding();
	try
	{
		rb_require("win32ole");
		VALUE v = rb_eval_string("WIN32OLE");
		// override original constructor
		rb_define_singleton_method(v, "new", reinterpret_cast<VALUE(*)(...)>(fole_s_new), -1);
		rb_define_singleton_method(v, "connect", reinterpret_cast<VALUE(*)(...)>(fole_s_connect), 1);
		rb_define_singleton_method(v, "attach", reinterpret_cast<VALUE(*)(...)>(foleex_attach), 2);
		rb_define_method(v, "__release", reinterpret_cast<VALUE(*)(...)>(foleex_release), 0);
		rb_define_method(v, "method_missing", reinterpret_cast<VALUE(*)(...)>(foleex_missing), -1);
		rb_define_method(v, "each", reinterpret_cast<VALUE(*)(...)>(foleex_each), 0);
		if (rb_const_defined_at(v, rb_intern("ARGV")) == Qfalse)
		{
			rb_define_const(v, "ARGV", rb_ary_new());
		}
		s_valueWin32Ole = v;
		s_valueWIN32OLERuntimeError = rb_eval_string("WIN32OLERuntimeError");
		v = rb_define_class("WIN32OLEEX", v);
		s_valueWin32OleEx = v;
		rb_define_singleton_method(v, "attach", reinterpret_cast<VALUE(*)(...)>(foleex_attach), 2);
		rb_define_method(v, "method_missing", reinterpret_cast<VALUE(*)(...)>(foleex_missing), -1);
		//
		s_valueActiveRubyScript = rb_define_class("ActiveScriptRuby", rb_cObject);
		rb_define_singleton_method(s_valueActiveRubyScript, "trace", (VALUE(*)(...))trace_hook, 6);
		rb_define_singleton_method(s_valueActiveRubyScript, "settrace", (VALUE(*)(...))trace_set, 1);
		rb_define_singleton_method(s_valueActiveRubyScript, "rubyize", (VALUE(*)(...))rubyize, 1);
	}
	catch (...)
	{
		ATLTRACE(_T("Exception for class\n"));
	}
}
Exemplo n.º 4
0
int
Init_enc_set_filesystem_encoding(void)
{
    int idx;
#if defined NO_LOCALE_CHARMAP
# error NO_LOCALE_CHARMAP defined
#elif defined _WIN32 || defined __CYGWIN__
    char cp[SIZEOF_CP_NAME];
    CP_FORMAT(cp, AreFileApisANSI() ? GetACP() : GetOEMCP());
    idx = rb_enc_find_index(cp);
    if (idx < 0) idx = ENCINDEX_ASCII;
#else
    idx = rb_enc_to_index(rb_default_external_encoding());
#endif
    return idx;
}
Exemplo n.º 5
0
/*
 *	call-seq:
 *		blob.text(max_lines = -1, encoding = Encoding.default_external) -> String
 *
 *	Return up to +max_lines+ of text from a blob as a +String+.
 *
 *	In Ruby 1.9.x, the string is created with the given +encoding+,
 *	defaulting to Encoding.default_external.
 *
 *	In previous versions, the +encoding+ argument is dummy and has no
 *	effect on the returned string.
 *
 *	When limiting the size of the text with +max_lines+, the string is
 *	expected to have an ASCII-compatible encoding, and is checked
 *	for the newline +\n+ character.
 */
static VALUE rb_git_blob_text_GET(int argc, VALUE *argv, VALUE self)
{
#ifdef HAVE_RUBY_ENCODING_H
	rb_encoding *encoding = rb_default_external_encoding();
#endif

	git_blob *blob;
	size_t size;
	const char *content;
	VALUE rb_max_lines, rb_encoding;

	Data_Get_Struct(self, git_blob, blob);
	rb_scan_args(argc, argv, "02", &rb_max_lines, &rb_encoding);

	content = git_blob_rawcontent(blob);
	size = git_blob_rawsize(blob);

	if (!NIL_P(rb_max_lines)) {
		size_t i = 0;
		int lines = 0, maxlines;

		Check_Type(rb_max_lines, T_FIXNUM);
		maxlines = FIX2INT(rb_max_lines);

		if (maxlines >= 0) {
			while (i < size && lines < maxlines) {
				if (content[i++] == '\n')
					lines++;
			}
		}

		size = (size_t)i;
	}

#ifdef HAVE_RUBY_ENCODING_H
	if (!NIL_P(rb_encoding)) {
		encoding = rb_to_encoding(rb_encoding);
	}
#endif

	if (size == 0)
		return rugged_str_new("", 0, encoding);

	return rugged_str_new(content, size, encoding);
}
Exemplo n.º 6
0
Arquivo: encoding.c Projeto: 217/ruby
VALUE
rb_enc_default_external(void)
{
    return rb_enc_from_encoding(rb_default_external_encoding());
}
Exemplo n.º 7
0
VALUE ruv_buffer_write(int argc, VALUE* argv, VALUE rb_buffer) {
    VALUE           rb_str, rb_offset, rb_length, rb_extern_enc, rb_cBuffer;
    size_t          offset, length, max_length, char_count;
    ruv_buffer_t    *buffer;
    rb_encoding     *rb_extern_encoding;

    Data_Get_Struct(rb_buffer, ruv_buffer_t, buffer);

    rb_scan_args(argc, argv, "13", &rb_str, &rb_offset, &rb_length, &rb_extern_enc);
    StringValue(rb_str);

    // encoding: use specified external encoding if provided
    // otherwise use Encoding.default_external as default
    if(!NIL_P(rb_extern_enc)) {
        rb_extern_encoding = rb_enc_get(rb_extern_enc);
    } else {
        rb_extern_encoding = rb_default_external_encoding();
    }

    // convert to external encoding
    rb_str = rb_str_export_to_enc(rb_str, rb_extern_encoding);

    // offset: either specified in params or 0
    if(!NIL_P(rb_offset)) {
        Check_Type(rb_offset, T_FIXNUM);
        offset = NUM2SIZET(rb_offset);
        if(offset >= buffer->length) {
            rb_raise(rb_eArgError, "Overflow! offset is larger than buffer size.");
        }
    } else {
        offset = 0;
    }

    // max length: the smaller of the max available space or the whole ruby string
    max_length = MIN(buffer->length - offset, (size_t)RSTRING_LEN(rb_str));

    // length: number of bytes to write. (include half chars)
    if(!NIL_P(rb_length)) {
        Check_Type(rb_length, T_FIXNUM);
        length = NUM2SIZET(rb_length);
    } else {
        length = max_length;
    }

    // If we are not writing the whole string into the buffer,
    // re-adjust length so we don't write half a character (uft8, etc)
    // 1). get char count from calculated byte length
    // 2). get byte length back from char count
    // This way only whole char is written to buffer
    if(length != (size_t)RSTRING_LEN(rb_str)) {
        char_count  = rb_str_sublen(rb_str, length);
        length      = rb_str_offset(rb_str, char_count);
    }

    memcpy(buffer->data + offset, RSTRING_PTR(rb_str), length);

    // set instance variable so we know how much characters are written
    rb_cBuffer = rb_obj_class(rb_buffer);
    rb_iv_set(rb_cBuffer, RUV_BUFFER_CHAR_WRITTEN_SYM, SIZET2NUM(char_count));

    return SIZET2NUM(length);
}
Exemplo n.º 8
0
int
Init_enc_set_filesystem_encoding(void)
{
    return rb_enc_to_index(rb_default_external_encoding());
}
Exemplo n.º 9
0
static VALUE encoding_spec_rb_default_external_encoding(VALUE self) {
  rb_encoding* enc = rb_default_external_encoding();
  if(enc == 0) return Qnil;
  return rb_str_new2(enc->name);
}