예제 #1
0
void fortitude_escaped_strcpy(VALUE rb_output, const char * src, int for_attribute_value) {
    char buf[BUF_SIZE + 1];
    char* buf_pos = buf;
    char* max_buf_pos = buf + (BUF_SIZE - MAX_SUBSTITUTION_LENGTH);
    char ch;

    while (1) {
        if (buf_pos >= max_buf_pos) {
            *buf_pos = '\0';
            rb_str_cat2(rb_output, buf);
            buf_pos = buf;
        }

        ch = *src;

        if (ch == '&') {
            *buf_pos++ = '&';
            *buf_pos++ = 'a';
            *buf_pos++ = 'm';
            *buf_pos++ = 'p';
            *buf_pos++ = ';';
        } else if (ch == '"') {
            *buf_pos++ = '&';
            *buf_pos++ = 'q';
            *buf_pos++ = 'u';
            *buf_pos++ = 'o';
            *buf_pos++ = 't';
            *buf_pos++ = ';';
        } else if (ch == '<' && (! for_attribute_value)) {
            *buf_pos++ = '&';
            *buf_pos++ = 'l';
            *buf_pos++ = 't';
            *buf_pos++ = ';';
        } else if (ch == '>' && (! for_attribute_value)) {
            *buf_pos++ = '&';
            *buf_pos++ = 'g';
            *buf_pos++ = 't';
            *buf_pos++ = ';';
        } else if (ch == '\'' && (! for_attribute_value)) {
            *buf_pos++ = '&';
            *buf_pos++ = '#';
            *buf_pos++ = '3';
            *buf_pos++ = '9';
            *buf_pos++ = ';';
        } else {
            if (ch == '\0') {
                break;
            }

            *buf_pos++ = ch;
        }

        src++;
    }

    if (buf_pos > buf) {
        *buf_pos = '\0';
        rb_str_cat2(rb_output, buf);
    }
}
예제 #2
0
파일: error.c 프로젝트: ferrous26/MacRuby
static void
err_append(const char *s)
{

    if (rb_vm_parse_in_eval()) {
	VALUE err = rb_errinfo();
	if (err == Qnil) {
	    err = rb_exc_new2(rb_eSyntaxError, s);
	    rb_set_errinfo(err);
	}
	else {
	    VALUE str = rb_obj_as_string(err);

	    rb_str_cat2(str, "\n");
	    rb_str_cat2(str, s);
	    rb_set_errinfo(rb_exc_new3(rb_eSyntaxError, str));
	}
    }
    else {
	VALUE err = rb_vm_current_exception();
	if (err == Qnil) {
	    err = rb_exc_new2(rb_eSyntaxError, "compile error");
	    rb_vm_set_current_exception(err);
	}
	rb_write_error(s);
	rb_write_error("\n");
    }
}
예제 #3
0
파일: error.c 프로젝트: AdamDotCom/my-rvm
static void
err_append(const char *s)
{
    rb_thread_t *th = GET_THREAD();
    VALUE err = th->errinfo;

    if (th->mild_compile_error) {
	if (!RTEST(err)) {
	    err = rb_exc_new2(rb_eSyntaxError, s);
	    th->errinfo = err;
	}
	else {
	    VALUE str = rb_obj_as_string(err);

	    rb_str_cat2(str, "\n");
	    rb_str_cat2(str, s);
	    th->errinfo = rb_exc_new3(rb_eSyntaxError, str);
	}
    }
    else {
	if (!RTEST(err)) {
	    err = rb_exc_new2(rb_eSyntaxError, "compile error");
	    th->errinfo = err;
	}
	rb_write_error(s);
	rb_write_error("\n");
    }
}
예제 #4
0
파일: windownload.c 프로젝트: kannans/shoes
SHOES_DOWNLOAD_HEADERS
shoes_http_headers(VALUE hsh)
{
    long i;
    LPWSTR hdrs = NULL;
    VALUE keys = rb_funcall(hsh, s_keys, 0);
    if (RARRAY_LEN(keys) > 0)
    {
        VALUE headers = rb_str_new2("");
        //for (i = 0; i < RARRAY(keys)->as.heap.len; i++ )
        for (i = 0; i < RARRAY_LEN(keys); i++ )
        {
            VALUE key = rb_ary_entry(keys, i);
            rb_str_append(headers, key);
            rb_str_cat2(headers, ": ");
            rb_str_append(headers, rb_hash_aref(hsh, key));
            rb_str_cat2(headers, "\n");
        }

        hdrs = SHOE_ALLOC_N(WCHAR, RSTRING_LEN(headers) + 1);
        SHOE_MEMZERO(hdrs, WCHAR, RSTRING_LEN(headers) + 1);
        MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(headers), -1, hdrs, RSTRING_LEN(headers) + 1);
    }
    return hdrs;
}
예제 #5
0
파일: variable.c 프로젝트: amtep/ruby
static VALUE
fc_path(struct fc_result *fc, ID name)
{
    VALUE path, tmp;

    path = rb_str_dup(rb_id2str(name));
    while (fc) {
	st_data_t n;
	if (fc->track == rb_cObject) break;
	if (RCLASS_IV_TBL(fc->track) &&
	    st_lookup(RCLASS_IV_TBL(fc->track), (st_data_t)classpath, &n)) {
	    tmp = rb_str_dup((VALUE)n);
	    rb_str_cat2(tmp, "::");
	    rb_str_append(tmp, path);
	    path = tmp;
	    break;
	}
	tmp = rb_str_dup(rb_id2str(fc->name));
	rb_str_cat2(tmp, "::");
	rb_str_append(tmp, path);
	path = tmp;
	fc = fc->prev;
    }
    OBJ_FREEZE(path);
    return path;
}
예제 #6
0
static void
compile_err_append(VALUE mesg)
{
    rb_thread_t *th = GET_THREAD();
    VALUE err = th->errinfo;
    rb_block_t *prev_base_block = th->base_block;
    th->base_block = 0;
    /* base_block should be zero while normal Ruby execution */
    /* after this line, any Ruby code *can* run */

    if (th->mild_compile_error) {
	if (RTEST(err)) {
	    VALUE str = rb_obj_as_string(err);

	    rb_str_cat2(str, "\n");
	    rb_str_append(str, mesg);
	    mesg = str;
	}
	err = rb_exc_new3(rb_eSyntaxError, mesg);
	th->errinfo = err;
    }
    else {
	if (!RTEST(err)) {
	    err = rb_exc_new2(rb_eSyntaxError, "compile error");
	    th->errinfo = err;
	}
	rb_str_cat2(mesg, "\n");
	rb_write_error_str(mesg);
    }

    /* returned to the parser world */
    th->base_block = prev_base_block;
}
예제 #7
0
static void end_element_ns_callback(void *ctx,
  					                        const xmlChar *xlocalname, const xmlChar *xprefix, const xmlChar *xURI)
{
  VALUE handler = (VALUE) ctx;

  if (handler == Qnil)
    return;

  /* Call end element for old-times sake */
  if (rb_respond_to(handler, cbidOnEndElement))
  {
    VALUE name;
    if (xprefix)
    {
      name = rb_str_new2(xprefix);
      rb_str_cat2(name, ":"); 
      rb_str_cat2(name, xlocalname); 
    }
    else
    {
      name = rb_str_new2(xlocalname);
    }
    rb_funcall(handler, cbidOnEndElement, 1, name);
  }

  rb_funcall(handler, cbidOnEndElementNs, 3, 
             rb_str_new2(xlocalname),
             xprefix ? rb_str_new2(xprefix) : Qnil,
             xURI ? rb_str_new2(xURI) : Qnil);
}
예제 #8
0
static VALUE rb_smbdir_read(VALUE self)
{
  RB_SMBFILE_DATA_FROM_OBJ(self, data);
  RB_SMBFILE_DATA_CLOSED(data);
  smbc_readdir_fn fn;
  struct smbc_dirent *smbcdent;

  fn = smbc_getFunctionReaddir(data->smbcctx);

  errno = 0;
  smbcdent = (*fn)(data->smbcctx, data->smbcfile);

  if (smbcdent == NULL) {
    if (errno) {
      rb_sys_fail(data->url);
    }

    return Qnil;
  }

  VALUE args[4];
  args[0] = rb_external_str_new_with_enc(smbcdent->name,
      strlen(smbcdent->name), data->enc);
  args[1] = INT2NUM(smbcdent->smbc_type);
  args[2] = rb_str_new2(data->url);
  rb_str_cat2(args[2], "/"); /* FIXME: Unless if the last char is not "/" */
  rb_str_cat2(args[2], smbcdent->name); /* FIXME: Must be URL encoding */
  args[3] = rb_str_new(smbcdent->comment, smbcdent->commentlen);
  VALUE entry_obj = rb_class_new_instance(4, args, rb_cSMBDirEntry);

  return entry_obj;
}
예제 #9
0
파일: map.c 프로젝트: 2007750219/protobuf
/*
 * call-seq:
 *     Map.inspect => string
 *
 * Returns a string representing this map's elements. It will be formatted as
 * "{key => value, key => value, ...}", with each key and value string
 * representation computed by its own #inspect method.
 */
VALUE Map_inspect(VALUE _self) {
  Map* self = ruby_to_Map(_self);

  VALUE str = rb_str_new2("{");

  bool first = true;
  VALUE inspect_sym = rb_intern("inspect");

  upb_strtable_iter it;
  for (upb_strtable_begin(&it, &self->table);
       !upb_strtable_done(&it);
       upb_strtable_next(&it)) {
    VALUE key = table_key_to_ruby(
        self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));

    upb_value v = upb_strtable_iter_value(&it);
    void* mem = value_memory(&v);
    VALUE value = native_slot_get(self->value_type,
                                  self->value_type_class,
                                  mem);

    if (!first) {
      str = rb_str_cat2(str, ", ");
    } else {
      first = false;
    }
    str = rb_str_append(str, rb_funcall(key, inspect_sym, 0));
    str = rb_str_cat2(str, "=>");
    str = rb_str_append(str, rb_funcall(value, inspect_sym, 0));
  }

  str = rb_str_cat2(str, "}");
  return str;
}
예제 #10
0
/* ================  Helper Functions  =================*/
static VALUE
figure_singleton_name(VALUE klass)
{
    VALUE result = Qnil;

    /* We have come across a singleton object. First
       figure out what it is attached to.*/
    VALUE attached = rb_iv_get(klass, "__attached__");

    /* Is this a singleton class acting as a metaclass? */
    if (BUILTIN_TYPE(attached) == T_CLASS)
    {
        result = rb_str_new2("<Class::");
        rb_str_append(result, rb_inspect(attached));
        rb_str_cat2(result, ">");
    }

    /* Is this for singleton methods on a module? */
    else if (BUILTIN_TYPE(attached) == T_MODULE)
    {
        result = rb_str_new2("<Module::");
        rb_str_append(result, rb_inspect(attached));
        rb_str_cat2(result, ">");
    }

    /* Is this for singleton methods on an object? */
    else if (BUILTIN_TYPE(attached) == T_OBJECT)
    {
        /* Make sure to get the super class so that we don't
           mistakenly grab a T_ICLASS which would lead to
           unknown method errors. */
#ifdef HAVE_RB_CLASS_SUPERCLASS
        // 1.9.3
        VALUE super = rb_class_superclass(klass);
#else
# ifdef RCLASS_SUPER
        VALUE super = rb_class_real(RCLASS_SUPER(klass));
# else
        VALUE super = rb_class_real(RCLASS(klass)->super);
# endif
#endif
        result = rb_str_new2("<Object::");
        rb_str_append(result, rb_inspect(super));
        rb_str_cat2(result, ">");
    }

    /* Ok, this could be other things like an array made put onto
       a singleton object (yeah, it happens, see the singleton
       objects test case). */
    else
    {
        result = rb_inspect(klass);
    }

    return result;
}
예제 #11
0
파일: ldap.c 프로젝트: henrikhodne/rldap
static VALUE rldap_inspect(VALUE obj)
{
	VALUE ruri, ret;
	
	ruri = rb_funcall(rldap_uri(obj), rb_intern("dump"), 0);
	ret = rb_str_new2("#<LDAP @uri=");
	rb_str_cat2(ret, StringValuePtr(ruri));
	rb_str_cat2(ret, ">");
	
	return ret;
}
예제 #12
0
파일: message.c 프로젝트: goodleon/protobuf
/*
 * call-seq:
 *     Message.inspect => string
 *
 * Returns a human-readable string representing this message. It will be
 * formatted as "<MessageType: field1: value1, field2: value2, ...>". Each
 * field's value is represented according to its own #inspect method.
 */
VALUE Message_inspect(VALUE _self) {
  MessageHeader* self;
  TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);

  VALUE str = rb_str_new2("<");
  str = rb_str_append(str, rb_str_new2(rb_class2name(CLASS_OF(_self))));
  str = rb_str_cat2(str, ": ");
  str = rb_str_append(str, layout_inspect(
      self->descriptor->layout, Message_data(self)));
  str = rb_str_cat2(str, ">");
  return str;
}
예제 #13
0
void
pg_define_coder( const char *name, void *func, VALUE klass, VALUE nsp )
{
  VALUE type_obj = Data_Wrap_Struct( klass, NULL, NULL, func );
	VALUE objname = rb_str_dup(rb_mod_name(nsp));
	rb_str_cat2( objname, "::");
	rb_str_cat2( objname, name);

  rb_iv_set( type_obj, "@name", rb_obj_freeze(objname) );
  rb_define_const( nsp, name, rb_obj_freeze(type_obj) );

  RB_GC_GUARD(type_obj);
}
예제 #14
0
파일: error.c 프로젝트: knugie/ruby
static VALUE
compile_snprintf(rb_encoding *enc, const char *pre, const char *file, int line, const char *fmt, va_list args)
{
    VALUE str = rb_enc_str_new(0, 0, enc);

    if (file) {
	rb_str_cat2(str, file);
	if (line) rb_str_catf(str, ":%d", line);
	rb_str_cat2(str, ": ");
    }
    if (pre) rb_str_cat2(str, pre);
    rb_str_vcatf(str, fmt, args);
    return str;
}
예제 #15
0
파일: error.c 프로젝트: 1nueve/MacRuby
/* :nodoc: */
static VALUE
name_err_mesg_to_str(VALUE obj, SEL sel)
{
    VALUE *ptr, mesg;
    Data_Get_Struct(obj, VALUE, ptr);

    mesg = ptr[0];
    if (NIL_P(mesg)) {
	return Qnil;
    }
    else {
	const char *desc = 0;
	VALUE d = 0, args[3];

	obj = ptr[1];
	switch (TYPE(obj)) {
	  case T_NIL:
	    desc = "nil";
	    break;
	  case T_TRUE:
	    desc = "true";
	    break;
	  case T_FALSE:
	    desc = "false";
	    break;
	  default:
	    d = rb_protect(safe_inspect, obj, NULL);
	    if (NIL_P(d) || RSTRING_LEN(d) > 65) {
		d = rb_any_to_s(obj);
	    }
	    desc = RSTRING_PTR(d);
	    break;
	}
	if (desc && desc[0] != '#') {
	    d = d ? rb_str_dup(d) : rb_str_new2(desc);
	    rb_str_cat2(d, ":");
	    rb_str_cat2(d, rb_obj_classname(obj));
	}
	args[0] = mesg;
	args[1] = ptr[2];
	args[2] = d;
	mesg = rb_f_sprintf(3, args);
    }
    if (OBJ_TAINTED(obj)) {
	OBJ_TAINT(mesg);
    }
    return mesg;
}
예제 #16
0
void fortitude_append_to(VALUE object, VALUE rb_output, int for_attribute_value) {
    ID to_s;
    char buf[25];
    long value;
    int i;
    VALUE new_string, array_element;

#ifdef CONST_ID
    CONST_ID(to_s, "to_s");
#else
    to_s = rb_intern("to_s");
#endif

    switch (TYPE(object)) {
        case T_STRING:
            fortitude_escaped_strcpy(rb_output, RSTRING_PTR(object), for_attribute_value);
            break;

        case T_SYMBOL:
            fortitude_escaped_strcpy(rb_output, rb_id2name(SYM2ID(object)), for_attribute_value);
            break;

        case T_ARRAY:
            value = RARRAY_LEN(object);
            for (i = 0; i < value; ++i) {
                array_element = rb_ary_entry(object, i);
                if (i > 0) {
                    rb_str_cat2(rb_output, " ");
                }
                fortitude_append_to(array_element, rb_output, for_attribute_value);
            }

        case T_NONE:
        case T_NIL:
            break;

        case T_FIXNUM:
            value = NUM2LONG(object);
            sprintf(buf, "%ld", value);
            rb_str_cat2(rb_output, buf);
            break;

        default:
            new_string = rb_funcall(object, to_s, 0);
            fortitude_escaped_strcpy(rb_output, RSTRING_PTR(new_string), for_attribute_value);
            break;
    }
}
예제 #17
0
static VALUE
oletypelib_path(VALUE guid, VALUE version)
{
    int k;
    LONG err;
    HKEY hkey;
    HKEY hlang;
    VALUE lang;
    VALUE path = Qnil;

    VALUE key = rb_str_new2("TypeLib\\");
    rb_str_concat(key, guid);
    rb_str_cat2(key, "\\");
    rb_str_concat(key, version);

    err = reg_open_vkey(HKEY_CLASSES_ROOT, key, &hkey);
    if (err != ERROR_SUCCESS) {
        return Qnil;
    }
    for(k = 0; path == Qnil; k++) {
        lang = reg_enum_key(hkey, k);
        if (lang == Qnil)
            break;
        err = reg_open_vkey(hkey, lang, &hlang);
        if (err == ERROR_SUCCESS) {
            path = reg_get_typelib_file_path(hlang);
            RegCloseKey(hlang);
        }
    }
    RegCloseKey(hkey);
    return path;
}
예제 #18
0
파일: ossl_ssl.c 프로젝트: 2220142/ruby
/*
 * call-seq:
 *    ctx.ciphers = "cipher1:cipher2:..."
 *    ctx.ciphers = [name, ...]
 *    ctx.ciphers = [[name, version, bits, alg_bits], ...]
 */
static VALUE
ossl_sslctx_set_ciphers(VALUE self, VALUE v)
{
    SSL_CTX *ctx;
    VALUE str, elem;
    int i;

    rb_check_frozen(self);
    if (NIL_P(v))
	return v;
    else if (TYPE(v) == T_ARRAY) {
        str = rb_str_new(0, 0);
        for (i = 0; i < RARRAY_LEN(v); i++) {
            elem = rb_ary_entry(v, i);
            if (TYPE(elem) == T_ARRAY) elem = rb_ary_entry(elem, 0);
            elem = rb_String(elem);
            rb_str_append(str, elem);
            if (i < RARRAY_LEN(v)-1) rb_str_cat2(str, ":");
        }
    } else {
        str = v;
        StringValue(str);
    }

    Data_Get_Struct(self, SSL_CTX, ctx);
    if(!ctx){
        ossl_raise(eSSLError, "SSL_CTX is not initialized.");
        return Qnil;
    }
    if (!SSL_CTX_set_cipher_list(ctx, RSTRING_PTR(str))) {
        ossl_raise(eSSLError, "SSL_CTX_set_cipher_list:");
    }

    return v;
}
예제 #19
0
static VALUE superclass_name(VALUE module)
{
  if(TYPE(module) == T_MODULE)
  {
    return Qnil;
  }
  else
  {
    VALUE super = RCLASS_SUPER(module);

    while(TYPE(super) == T_ICLASS)
    {
      super = RCLASS_SUPER(super);
    }

    if(!super)
    {
      return Qnil;
    }

    if(FL_TEST(super, FL_SINGLETON))
    {
      VALUE v = rb_iv_get(super, "__attached__");
      VALUE name = rb_mod_name(v);
      rb_str_cat2(name, "::<Singleton>");
      return name;
    }
    else
    {
      return rb_mod_name(super);
    }
  }
}
예제 #20
0
파일: variable.c 프로젝트: kyab/MacRuby
void
rb_set_class_path2(VALUE klass, VALUE under, const char *name, VALUE outer)
{
    VALUE str;

    if (under == rb_cObject) {
	str = rb_str_new2(name);
    }
    else {
	str = rb_str_dup(rb_class_path(under));
	rb_str_cat2(str, "::");
	rb_str_cat2(str, name);
    }
    OBJ_FREEZE(str);
    rb_ivar_set(klass, id_classpath, str);
}
예제 #21
0
파일: ngraph.c 프로젝트: htrb/ngraph-gtk
static VALUE
create_obj_arg(VALUE args)
{
  int i, n;
  VALUE arg, str, uniq_args;
  struct ngraph_instance *inst;
  struct objlist *obj = NULL;
  const char *name;

  uniq_args = rb_funcall(args, Uniq, 0);
  n = RARRAY_LEN(uniq_args);
  str = rb_str_new2("");
  for (i = 0; i < n; i++) {
    arg = rb_ary_entry(uniq_args, i);
    if (! rb_obj_is_kind_of(arg, NgraphClass)) {
      return Qnil;
    }

    inst = check_id(arg);
    if (inst == NULL) {
      return Qnil;
    }

    if (obj == NULL) {
      obj = inst->obj;
      name = ngraph_get_object_name(inst->obj);
      rb_str_cat2(str, name);
    } else if (obj != inst->obj) {
      return Qnil;
    }
    rb_str_catf(str, "%c%d", (i) ? ',' : ':', inst->id);
  }
  return str;
}
예제 #22
0
static VALUE
ossl_engine_inspect(VALUE self)
{
    VALUE str;
    const char *cname = rb_class2name(rb_obj_class(self));

    str = rb_str_new2("#<");
    rb_str_cat2(str, cname);
    rb_str_cat2(str, " id=\"");
    rb_str_append(str, ossl_engine_get_id(self));
    rb_str_cat2(str, "\" name=\"");
    rb_str_append(str, ossl_engine_get_name(self));
    rb_str_cat2(str, "\">");

    return str;
}
예제 #23
0
static VALUE
full_name(VALUE klass, ID mid)
{
  VALUE result = klass_name(klass);
  rb_str_cat2(result, "#");
  rb_str_append(result, method_name(mid));
  return result;
}
예제 #24
0
파일: struct.c 프로젝트: Chatto/VGdesk
static VALUE
inspect_struct(VALUE s, VALUE dummy, int recur)
{
    VALUE cname = rb_class_name(rb_obj_class(s));
    VALUE members, str = rb_str_new2("#<struct ");
    VALUE *ptr, *ptr_members;
    long i, len;
    char first = RSTRING_PTR(cname)[0];

    if (recur || first != '#') {
	rb_str_append(str, cname);
    }
    if (recur) {
	return rb_str_cat2(str, ":...>");
    }

    members = rb_struct_members(s);
    ptr_members = RARRAY_PTR(members);
    ptr = RSTRUCT_PTR(s);
    len = RSTRUCT_LEN(s);
    for (i=0; i<len; i++) {
	VALUE slot;
	ID id;

	if (i > 0) {
	    rb_str_cat2(str, ", ");
	}
	else if (first != '#') {
	    rb_str_cat2(str, " ");
	}
	slot = ptr_members[i];
	id = SYM2ID(slot);
	if (rb_is_local_id(id) || rb_is_const_id(id)) {
	    rb_str_append(str, rb_id2str(id));
	}
	else {
	    rb_str_append(str, rb_inspect(slot));
	}
	rb_str_cat2(str, "=");
	rb_str_append(str, rb_inspect(ptr[i]));
    }
    rb_str_cat2(str, ">");
    OBJ_INFECT(str, s);

    return str;
}
예제 #25
0
파일: error.c 프로젝트: knugie/ruby
void
rb_load_fail(VALUE path, const char *err)
{
    VALUE mesg = rb_str_buf_new_cstr(err);
    rb_str_cat2(mesg, " -- ");
    rb_str_append(mesg, path);	/* should be ASCII compatible */
    raise_loaderror(path, mesg);
}
예제 #26
0
파일: error.c 프로젝트: knugie/ruby
static void
warn_print(const char *fmt, va_list args)
{
    VALUE str = rb_str_new(0, 0);
    VALUE file = rb_sourcefilename();

    if (!NIL_P(file)) {
	int line = rb_sourceline();
	str = rb_str_append(str, file);
	if (line) rb_str_catf(str, ":%d", line);
	rb_str_cat2(str, ": ");
    }

    rb_str_cat2(str, "warning: ");
    rb_str_vcatf(str, fmt, args);
    rb_str_cat2(str, "\n");
    rb_write_error_str(str);
}
예제 #27
0
파일: error.c 프로젝트: knugie/ruby
static void
compile_warn_print(const char *file, int line, const char *fmt, va_list args)
{
    VALUE str;

    str = compile_snprintf(NULL, "warning: ", file, line, fmt, args);
    rb_str_cat2(str, "\n");
    rb_write_error_str(str);
}
예제 #28
0
static VALUE rb_tokenizer_extract_tokens(VALUE self, VALUE rb_data) {
	YY_BUFFER_STATE buf;
	yyscan_t scanner;
	struct tokenizer_extra extra;
	VALUE ary, s;
	long len;
	int r;

	Check_Type(rb_data, T_STRING);

	len = RSTRING_LEN(rb_data);
	if (len > 100000)
		len = 100000;

	linguist_yylex_init_extra(&extra, &scanner);
	buf = linguist_yy_scan_bytes(RSTRING_PTR(rb_data), (int) len, scanner);

	ary = rb_ary_new();
	do {
		extra.type = NO_ACTION;
		extra.token = NULL;
		r = linguist_yylex(scanner);
		switch (extra.type) {
		case NO_ACTION:
			break;
		case REGULAR_TOKEN:
			len = strlen(extra.token);
			if (len <= MAX_TOKEN_LEN)
				rb_ary_push(ary, rb_str_new(extra.token, len));
			free(extra.token);
			break;
		case SHEBANG_TOKEN:
			len = strlen(extra.token);
			if (len <= MAX_TOKEN_LEN) {
				s = rb_str_new2("SHEBANG#!");
				rb_str_cat(s, extra.token, len);
				rb_ary_push(ary, s);
			}
			free(extra.token);
			break;
		case SGML_TOKEN:
			len = strlen(extra.token);
			if (len <= MAX_TOKEN_LEN) {
				s = rb_str_new(extra.token, len);
				rb_str_cat2(s, ">");
				rb_ary_push(ary, s);
			}
			free(extra.token);
			break;
		}
	} while (r);

	linguist_yy_delete_buffer(buf, scanner);
	linguist_yylex_destroy(scanner);

	return ary;
}
예제 #29
0
파일: ossl_ssl.c 프로젝트: 2220142/ruby
/*
 * call-seq:
 *    ssl.state => string
 */
static VALUE
ossl_ssl_get_state(VALUE self)
{
    SSL *ssl;
    VALUE ret;

    Data_Get_Struct(self, SSL, ssl);
    if (!ssl) {
        rb_warning("SSL session is not started yet.");
        return Qnil;
    }
    ret = rb_str_new2(SSL_state_string(ssl));
    if (ruby_verbose) {
        rb_str_cat2(ret, ": ");
        rb_str_cat2(ret, SSL_state_string_long(ssl));
    }
    return ret;
}
예제 #30
0
static VALUE
warning_string(rb_encoding *enc, const char *fmt, va_list args)
{
    VALUE str = rb_enc_str_new(0, 0, enc);
    VALUE file = rb_sourcefilename();

    if (!NIL_P(file)) {
	int line = rb_sourceline();
	str = rb_str_append(str, file);
	if (line) rb_str_catf(str, ":%d", line);
	rb_str_cat2(str, ": ");
    }

    rb_str_cat2(str, "warning: ");
    rb_str_vcatf(str, fmt, args);
    rb_str_cat2(str, "\n");
    return str;
}