static VALUE t_invoke_popen (VALUE self UNUSED, VALUE cmd) { #ifdef OS_WIN32 rb_raise (EM_eUnsupported, "popen is not available on this platform"); #endif int len = RARRAY_LEN(cmd); if (len >= 2048) rb_raise (rb_eRuntimeError, "%s", "too many arguments to popen"); char *strings [2048]; for (int i=0; i < len; i++) { VALUE ix = INT2FIX (i); VALUE s = rb_ary_aref (1, &ix, cmd); strings[i] = StringValueCStr (s); } strings[len] = NULL; uintptr_t f = 0; try { f = evma_popen (strings); } catch (std::runtime_error e) { rb_raise (rb_eRuntimeError, "%s", e.what()); } if (!f) { char *err = strerror (errno); char buf[100]; memset (buf, 0, sizeof(buf)); snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???")); rb_raise (rb_eRuntimeError, "%s", buf); } return BSIG2NUM (f); }
static VALUE t_invoke_popen (VALUE self, VALUE cmd) { // 1.8.7+ #ifdef RARRAY_LEN int len = RARRAY_LEN(cmd); #else int len = RARRAY (cmd)->len; #endif if (len >= 2048) rb_raise (rb_eRuntimeError, "%s", "too many arguments to popen"); char *strings [2048]; for (int i=0; i < len; i++) { VALUE ix = INT2FIX (i); VALUE s = rb_ary_aref (1, &ix, cmd); strings[i] = StringValuePtr (s); } strings[len] = NULL; unsigned long f = 0; try { f = evma_popen (strings); } catch (std::runtime_error e) { f = 0; // raise exception below } if (!f) { char *err = strerror (errno); char buf[100]; memset (buf, 0, sizeof(buf)); snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???")); rb_raise (rb_eRuntimeError, "%s", buf); } return ULONG2NUM (f); }
static VALUE mlink_print_debug(VALUE obj) { VALUE link_mark, arg[1], link, mark; link_mark = mlink_get(obj); arg[0] = INT2FIX(0); link = rb_ary_aref(1, arg, link_mark); arg[0] = INT2FIX(1); mark = rb_ary_aref(1, arg, link_mark); rb_funcall(obj, rb_intern("puts"), 1, rb_funcall(rb_str_new2("#<MLink: @mark = %s, @link = 0x%014x>"), rb_intern("%"), 1, rb_ary_new3(2, mark, rb_funcall(link, rb_intern("object_id"), 0)) )); return Qnil; }
static VALUE array_spec_rb_ary_aref(int argc, VALUE *argv, VALUE self) { VALUE ary, args; rb_scan_args(argc, argv, "1*", &ary, &args); return rb_ary_aref((int)RARRAY_LEN(args), RARRAY_PTR(args), ary); }
static inline VALUE my_ary_subseq(VALUE ary, long idx, long len) { VALUE args[2] = { LONG2FIX(idx), LONG2FIX(len) }; return rb_ary_aref(2, args, ary); }
static CFTypeRef convert2cf_type(VALUE obj) { CFTypeRef result = NULL; double double_result; int int_result; long long_result; int i, len; VALUE tmp[1]; CFAbsoluteTime time; CFMutableArrayRef array_result; switch (TYPE(obj)) { case T_NIL: result = NULL; break; case T_TRUE: result = kCFBooleanTrue; break; case T_FALSE: result = kCFBooleanFalse; break; case T_FLOAT: double_result = NUM2DBL(obj); result = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &double_result); break; case T_BIGNUM: long_result = NUM2LONG(obj); result = CFNumberCreate(kCFAllocatorDefault, kCFNumberLongType, &long_result); break; case T_FIXNUM: int_result = FIX2INT(obj); result = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &int_result); break; case T_STRING: result = rbstr2cfstring(obj); break; case T_DATA: case T_OBJECT: // todo : check type is Time // 978307200.0 == (January 1, 2001 00:00 GMT) - (January 1, 1970 00:00 UTC) // CFAbsoluteTime => January 1, 2001 00:00 GMT // ruby Time => January 1, 1970 00:00 UTC if (rb_obj_is_kind_of(obj, rb_cTime)) { time = (CFAbsoluteTime) (NUM2DBL(rb_funcall(obj, rb_intern("to_f"), 0)) - 978307200.0); result = CFDateCreate(kCFAllocatorDefault, time); } break; case T_ARRAY: len = RARRAY_LEN(obj); array_result = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); for (i = 0; i < len; i++) { tmp[0] = INT2NUM(i); CFArrayAppendValue(array_result, convert2cf_type(rb_ary_aref(1, tmp, obj))); } result = array_result; break; default: rb_raise(rb_eTypeError, "not valid value"); break; } return result; }
VALUE rb_Fonts_get_shadow_color(VALUE self, VALUE id) { return rb_ary_aref(1, &id, rb_ivar_get(rb_mFonts, rb_Fonts_ivSColor)); }
VALUE rb_Fonts_get_outline_color(VALUE self, VALUE id) { return rb_ary_aref(1, &id, rb_ivar_get(rb_mFonts, rb_Fonts_ivOColor)); }
VALUE rb_Fonts_get_fill_color(VALUE self, VALUE id) { return rb_ary_aref(1, &id, rb_ivar_get(rb_mFonts, rb_Fonts_ivFColor)); }