예제 #1
0
파일: fastxml.c 프로젝트: segfault/fastxml
VALUE munge_xpath_namespace( VALUE orig_expr, xmlChar *root_ns )
{
	VALUE path_bits = rb_str_split( orig_expr, "/" );
	VALUE ns_prefix = rb_str_new2( (const char*)root_ns );
	VALUE ns_indic = rb_str_new2( ":" );
	VALUE slash = rb_str_new2( "/" );
	VALUE path_bit, str_idx;
	VALUE ret_ary = rb_ary_new();
	long i;
	
	rb_str_append( ns_prefix, ns_indic );
    for (i=0; i<RARRAY(path_bits)->len; i++) {
        path_bit = RARRAY(path_bits)->ptr[i];
		
		if (RSTRING_LEN(path_bit) > 0) {
			str_idx = rb_funcall( path_bit, rb_intern( "index" ), 1, ns_indic );
			if (str_idx == Qnil || str_idx == Qfalse) // didn't find the :, so it looks like we don't have a namespace
				path_bit = rb_str_plus( ns_prefix, path_bit );
		}	
		
		rb_ary_push( ret_ary, path_bit );
    }
	
	return rb_ary_join( ret_ary, slash );
}
예제 #2
0
파일: do_sqlite3.c 프로젝트: bmatcuk/do
VALUE do_sqlite3_cConnection_quote_byte_array(VALUE self, VALUE string) {
  VALUE source = StringValue(string);
  VALUE array = rb_funcall(source, rb_intern("unpack"), 1, rb_str_new2("H*"));

  rb_ary_unshift(array, rb_str_new2("X'"));
  rb_ary_push(array, rb_str_new2("'"));
  return rb_ary_join(array, Qnil);
}
예제 #3
0
/*
 *  call-seq:
 *    patch.to_s -> str
 *
 *  Returns the contents of the patch as a single diff string.
 */
static VALUE rb_git_diff_patch_to_s(VALUE self)
{
    git_patch *patch;
    VALUE rb_buffer = rb_ary_new();
    Data_Get_Struct(self, git_patch, patch);

    rugged_exception_check(git_patch_print(patch, patch_print_cb, (void*)rb_buffer));

    return rb_ary_join(rb_buffer, Qnil);
}
예제 #4
0
파일: group.c 프로젝트: dacamp/etcutils
static VALUE group_gr_sprintf(VALUE self)
{
  VALUE args[5];
  args[0] = setup_safe_str("%s:%s:%s:%s\n");
  args[1] = rb_ivar_get(self, id_name);
  args[2] = rb_ivar_get(self, id_passwd);
  args[3] = rb_ivar_get(self,id_gid);
  args[4] = rb_ary_join((VALUE)rb_iv_get(self, "@members"), (VALUE)setup_safe_str(","));
  return rb_f_sprintf(5, args);
}
예제 #5
0
파일: class.c 프로젝트: Danylyuk/first_app
static void
keyword_error(const char *error, VALUE keys)
{
    const char *msg = "";
    if (RARRAY_LEN(keys) == 1) {
	keys = RARRAY_AREF(keys, 0);
    }
    else {
	keys = rb_ary_join(keys, rb_usascii_str_new2(", "));
	msg = "s";
    }
    rb_raise(rb_eArgError, "%s keyword%s: %"PRIsVALUE, error, msg, keys);
}
예제 #6
0
/*
 *  call-seq:
 *    patch.header -> str
 *
 *  Returns only the header of the patch as a string.
 */
static VALUE rb_git_diff_patch_header(VALUE self)
{
    git_patch *patch;
    int error = 0;
    VALUE rb_buffer = rb_ary_new();
    Data_Get_Struct(self, git_patch, patch);

    error = git_patch_print(patch, patch_print_header_cb, (void*)rb_buffer);
    if (error && error != GIT_ITEROVER)
        rugged_exception_check(error);

    return rb_ary_join(rb_buffer, Qnil);
}
예제 #7
0
static VALUE
//iter_struct_inspect(na_loop_t *const lp)
iter_struct_inspect(char *ptr, size_t pos, VALUE opt)
{
    VALUE   types, defs, def, name, elmt, vary, v, x;
    size_t  ofs;
    long    i, len;
    narray_view_t *ne;

    types = RARRAY_AREF(opt,0);
    defs = RARRAY_AREF(opt,1);

    len = RARRAY_LEN(types);
    vary = rb_ary_new2(len);

    for (i=0; i<len; i++) {
        def  = RARRAY_AREF(defs,i);
        name = RARRAY_AREF(def,0);
        ofs  = NUM2SIZET(RARRAY_AREF(def,2));
        elmt = RARRAY_AREF(types,i);
        GetNArrayView(elmt,ne);
        ne->offset = pos + ofs;
        v = rb_str_concat(rb_sym_to_s(name), rb_str_new2(": "));
        x = rb_funcall(elmt, rb_intern("format_to_a"), 0);        // <-- fix me
        if (ne->base.ndim==0) {
            x = rb_funcall(x, rb_intern("first"), 0);
        }
        x = rb_funcall(x, rb_intern("to_s"), 0);
        v = rb_str_concat(v, x);
        rb_ary_push(vary, v);
    }
    v = rb_ary_join(vary, rb_str_new2(", "));
    v = rb_str_concat(rb_str_new2("["), v);
    v = rb_str_concat(v, rb_str_new2("]"));
    return v;
}
예제 #8
0
static VALUE cie_command(VALUE UNUSED(module), VALUE rmsg)
{
  char *msg = NULL;
  userinput *uxdl;

  if (NIL_P(rmsg))
    return Qnil;

  switch (TYPE(rmsg)) {
   case T_ARRAY:
     rmsg = rb_ary_join(rmsg, rb_str_new2(" "));
     /* process Array */
     /* fallthrough */
  case T_STRING:
     /* process String */
     msg = rb_obj_as_string_protected(rmsg);
     break;
   default:
     /* ignore */
     break;
  }
  if (!msg)
    return Qnil;

  uxdl = mycalloc(sizeof(userinput));
  ioutput(OUT_S|OUT_L|OUT_D, COLOR_MAGENTA, "RUBY %s", msg);

  a_fillwith_msg2(uxdl, NULL, msg);
  uxdl->method = method_console;
  uxdl->net = 0;
  uxdl->level = ADMIN_LEVEL_CONSOLE;
  u_parseit(uxdl);

  mydelete(uxdl);
  return Qtrue;
}
예제 #9
0
파일: lob.c 프로젝트: aq1018/ruby-oci8
static VALUE oci8_lob_read(int argc, VALUE *argv, VALUE self)
{
    oci8_lob_t *lob = DATA_PTR(self);
    oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
    ub4 length;
    ub4 nchar;
    ub4 amt;
    sword rv;
    char buf[8192];
    size_t buf_size_in_char;
    VALUE size;
    VALUE v = rb_ary_new();

    rb_scan_args(argc, argv, "01", &size);
    length = oci8_lob_get_length(lob);
    if (length <= lob->pos) /* EOF */
        return Qnil;
    length -= lob->pos;
    if (NIL_P(size)) {
        nchar = length; /* read until EOF */
    } else {
        nchar = NUM2UINT(size);
        if (nchar > length)
            nchar = length;
    }
    amt = nchar;
    buf_size_in_char = sizeof(buf) / lob->char_width;
    do {
        if (lob->state == S_BFILE_CLOSE) {
            rv = OCILobFileOpen_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, OCI_FILE_READONLY);
            if (rv == OCI_ERROR && oci8_get_error_code(oci8_errhp) == 22290) {
                /* ORA-22290: operation would exceed the maximum number of opened files or LOBs */
                /* close all opened BFILE implicitly. */
                oci8_base_t *base;
                for (base = &lob->base; base != &lob->base; base = base->next) {
                    if (base->type == OCI_DTYPE_LOB) {
                        oci8_lob_t *tmp = (oci8_lob_t *)base;
                        if (tmp->state == S_BFILE_OPEN) {
                            tmp->state = S_BFILE_CLOSE;
                        }
                    }
                }
                oci_lc(OCILobFileCloseAll_nb(svcctx, svcctx->base.hp.svc, oci8_errhp));
                continue;
            }
            if (rv != OCI_SUCCESS)
                oci8_raise(oci8_errhp, rv, NULL);
            lob->state = S_BFILE_OPEN;
        }
        /* initialize buf in zeros everytime to check a nul characters. */
        memset(buf, 0, sizeof(buf));
        rv = OCILobRead_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &amt, lob->pos + 1, buf, sizeof(buf), NULL, NULL, 0, lob->csfrm);
        if (rv == OCI_ERROR && oci8_get_error_code(oci8_errhp) == 22289) {
            /* ORA-22289: cannot perform FILEREAD operation on an unopened file or LOB */
            if (lob->state == S_BFILE_CLOSE)
                continue;
        }
        if (rv != OCI_SUCCESS && rv != OCI_NEED_DATA)
            oci8_raise(oci8_errhp, rv, NULL);

        /* Workaround when using Oracle 10.2.0.4 or 11.1.0.6 client and
         * variable-length character set (e.g. AL32UTF8).
         *
         * When the above mentioned condition, amt may be shorter. So
         * amt is increaded until a nul character to know the actually
         * read size.
         */
        while (amt < sizeof(buf) && buf[amt] != '\0') {
            amt++;
        }

        if (amt == 0)
            break;
        /* for fixed size charset, amt is the number of characters stored in buf. */
        if (amt > buf_size_in_char)
            rb_raise(eOCIException, "Too large buffer fetched or you set too large size of a character.");
        amt *= lob->char_width;
        rb_ary_push(v, rb_str_new(buf, amt));
    } while (rv == OCI_NEED_DATA);
    lob->pos += nchar;
    if (nchar == length) {
        lob_close(lob);
        bfile_close(lob);
    }
    if (RARRAY_LEN(v) == 0) {
        return Qnil;
    }
    v = rb_ary_join(v, Qnil);
    OBJ_TAINT(v);
    if (lob->lobtype == OCI_TEMP_CLOB) {
        /* set encoding */
        rb_enc_associate(v, oci8_encoding);
        return rb_str_conv_enc(v, oci8_encoding, rb_default_internal_encoding());
    } else {
        /* ASCII-8BIT */
        return v;
    }
}
예제 #10
0
static VALUE array_spec_rb_ary_join(VALUE self, VALUE array1, VALUE array2) {
  return rb_ary_join(array1, array2);
}
예제 #11
0
파일: initrb.c 프로젝트: numinit/initrb
static VALUE initrb_interpreter_print_exception(VALUE exception) {
    VALUE backtrace = rb_funcall(exception, rb_intern("backtrace"), 0);
    VALUE arr = rb_ary_new3(2, rb_obj_as_string(rb_obj_class(exception)), rb_obj_as_string(exception));
    rb_ary_push(arr, RARRAY_LENINT(backtrace) == 0 ? rb_str_new_cstr("(initrb)") : rb_ary_join(backtrace, rb_str_new_cstr("\n\tfrom ")));
    return rb_funcall(rb_stderr, rb_intern("puts"), 1, rb_str_format(RARRAY_LENINT(arr), RARRAY_PTR(arr), rb_str_new_cstr("%s: %s\nfrom %s")));
}
예제 #12
0
/*
 * @overload read
 *
 *  
 *
 *  @param [Integer] length number of characters if +self+ is a {CLOB} or a {NCLOB}.
 *    number of bytes if +self+ is a {BLOB} or a {BFILE}.
 *  @return [String or nil] data read. <code>nil</code> means it
 *    met EOF at beginning. It returns an empty string '' as a special exception
 *    when <i>length</i> is <code>nil</code> and the lob is empty.
 *
 * @overload read(length)
 *
 *  Reads <i>length</i> characters for {CLOB} and {NCLOB} or <i>length</i>
 *  bytes for {BLOB} and {BFILE} from the current position.
 *  If <i>length</i> is <code>nil</code>, it reads data until EOF.
 *
 *  @param [Integer] length number of characters if +self+ is a {CLOB} or a {NCLOB}.
 *    number of bytes if +self+ is a {BLOB} or a {BFILE}.
 *  @return [String or nil] data read. <code>nil</code> means it
 *    met EOF at beginning. It returns an empty string '' as a special exception
 *    when <i>length</i> is <code>nil</code> and the lob is empty.
 */
static VALUE oci8_lob_read(int argc, VALUE *argv, VALUE self)
{
    oci8_lob_t *lob = TO_LOB(self);
    oci8_svcctx_t *svcctx = check_svcctx(lob);
    ub8 lob_length;
    ub8 read_len;
    ub8 pos = lob->pos;
    long strbufsiz;
    ub8 byte_amt;
    ub8 char_amt;
    sword rv;
    VALUE size;
    VALUE v = rb_ary_new();
    OCIError *errhp = oci8_errhp;
    ub1 piece = OCI_FIRST_PIECE;

    rb_scan_args(argc, argv, "01", &size);
    lob_length = oci8_lob_get_length(lob);
    if (lob_length == 0 && NIL_P(size)) {
        return rb_usascii_str_new("", 0);
    }
    if (lob_length <= pos) /* EOF */
        return Qnil;
    if (NIL_P(size)) {
        read_len = lob_length - pos;
    } else {
        ub8 sz = NUM2ULL(size);
        read_len = MIN(sz, lob_length - pos);
    }
    if (lob->lobtype == OCI_TEMP_CLOB) {
        byte_amt = 0;
        char_amt = read_len;
        if (oci8_nls_ratio == 1) {
            strbufsiz = MIN(read_len, ULONG_MAX);
        } else {
            strbufsiz = MIN(read_len + read_len / 8, ULONG_MAX);
        }
        if (strbufsiz <= 10) {
            strbufsiz = 10;
        }
    } else {
        byte_amt = read_len;
        char_amt = 0;
        strbufsiz = MIN(read_len, ULONG_MAX);
    }
    if (lob->state == S_BFILE_CLOSE) {
        open_bfile(svcctx, lob, errhp);
    }
    do {
        VALUE strbuf = rb_str_buf_new(strbufsiz);
        char *buf = RSTRING_PTR(strbuf);

        rv = OCILobRead2_nb(svcctx, svcctx->base.hp.svc, errhp, lob->base.hp.lob, &byte_amt, &char_amt, pos + 1, buf, strbufsiz, piece, NULL, NULL, 0, lob->csfrm);
        svcctx->suppress_free_temp_lobs = 0;
        switch (rv) {
        case OCI_SUCCESS:
            break;
        case OCI_NEED_DATA:
            /* prevent OCILobFreeTemporary() from being called.
             * See: https://github.com/kubo/ruby-oci8/issues/20
             */
            svcctx->suppress_free_temp_lobs = 1;
            piece = OCI_NEXT_PIECE;
            break;
        default:
            chker2(rv, &svcctx->base);
        }
        if (byte_amt == 0)
            break;
        if (lob->lobtype == OCI_TEMP_CLOB) {
            pos += char_amt;
        } else {
            pos += byte_amt;
        }
        rb_str_set_len(strbuf, byte_amt);
        rb_ary_push(v, strbuf);
    } while (rv == OCI_NEED_DATA);

    if (pos >= lob_length) {
        lob_close(lob);
        bfile_close(lob);
    }
    lob->pos = pos;
    switch (RARRAY_LEN(v)) {
    case 0:
        return Qnil;
    case 1:
        v = RARRAY_AREF(v, 0);
        break;
    default:
        v = rb_ary_join(v, Qnil);
    }
    OBJ_TAINT(v);
    if (lob->lobtype == OCI_TEMP_CLOB) {
        /* set encoding */
        rb_enc_associate(v, oci8_encoding);
        return rb_str_conv_enc(v, oci8_encoding, rb_default_internal_encoding());
    } else {
        /* ASCII-8BIT */
        return v;
    }
}