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; }
static void showExc(VALUE exc) { VALUE bt = rb_funcall2(exc, rb_intern("backtrace"), 0, NULL); VALUE bt0 = rb_ary_entry(bt, 0); VALUE name = rb_class_path(rb_obj_class(exc)); VALUE ds = rb_sprintf("%" PRIsVALUE ": %" PRIsVALUE " (%" PRIsVALUE ")", bt0, exc, name); /* omit "useless" last entry (from ruby:1:in `eval') */ for (long i = 1, btlen = RARRAY_LEN(bt) - 1; i < btlen; ++i) rb_str_catf(ds, "\n\tfrom %" PRIsVALUE, rb_ary_entry(bt, i)); Debug() << StringValueCStr(ds); ID id_index = rb_intern("index"); /* an "offset" argument is not needed for the first time */ VALUE argv[2] = { rb_str_new_cstr(":") }; long filelen = NUM2LONG(rb_funcall2(bt0, id_index, 1, argv)); argv[1] = LONG2NUM(filelen + 1); VALUE tmp = rb_funcall2(bt0, id_index, ARRAY_SIZE(argv), argv); long linelen = NUM2LONG(tmp) - filelen - 1; VALUE file = rb_str_subseq(bt0, 0, filelen); VALUE line = rb_str_subseq(bt0, filelen + 1, linelen); VALUE ms = rb_sprintf("Script '%" PRIsVALUE "' line %" PRIsVALUE ": %" PRIsVALUE " occured.\n\n%" PRIsVALUE, file, line, name, exc); showMsg(StringValueCStr(ms)); }
static VALUE syserr_initialize(int argc, VALUE *argv, VALUE self) { #if !defined(_WIN32) char *strerror(); #endif const char *err; VALUE mesg, error, func, errmsg; VALUE klass = rb_obj_class(self); if (klass == rb_eSystemCallError) { st_data_t data = (st_data_t)klass; rb_scan_args(argc, argv, "12", &mesg, &error, &func); if (argc == 1 && FIXNUM_P(mesg)) { error = mesg; mesg = Qnil; } if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) { klass = (VALUE)data; /* change class */ if (!RB_TYPE_P(self, T_OBJECT)) { /* insurance to avoid type crash */ rb_raise(rb_eTypeError, "invalid instance type"); } RBASIC_SET_CLASS(self, klass); } } else { rb_scan_args(argc, argv, "02", &mesg, &func); error = rb_const_get(klass, rb_intern("Errno")); } if (!NIL_P(error)) err = strerror(NUM2INT(error)); else err = "unknown error"; errmsg = rb_enc_str_new_cstr(err, rb_locale_encoding()); if (!NIL_P(mesg)) { VALUE str = StringValue(mesg); if (!NIL_P(func)) rb_str_catf(errmsg, " @ %"PRIsVALUE, func); rb_str_catf(errmsg, " - %"PRIsVALUE, str); OBJ_INFECT(errmsg, mesg); } mesg = errmsg; rb_call_super(1, &mesg); rb_iv_set(self, "errno", error); return self; }
static void showExc(VALUE exc, const BacktraceData &btData) { VALUE bt = rb_funcall2(exc, rb_intern("backtrace"), 0, NULL); VALUE msg = rb_funcall2(exc, rb_intern("message"), 0, NULL); VALUE bt0 = rb_ary_entry(bt, 0); VALUE name = rb_class_path(rb_obj_class(exc)); VALUE ds = rb_sprintf("%" PRIsVALUE ": %" PRIsVALUE " (%" PRIsVALUE ")", bt0, exc, name); /* omit "useless" last entry (from ruby:1:in `eval') */ for (long i = 1, btlen = RARRAY_LEN(bt) - 1; i < btlen; ++i) rb_str_catf(ds, "\n\tfrom %" PRIsVALUE, rb_ary_entry(bt, i)); Debug() << StringValueCStr(ds); char *s = RSTRING_PTR(bt0); char line[16]; std::string file(512, '\0'); char *p = s + strlen(s); char *e; while (p != s) if (*--p == ':') break; e = p; while (p != s) if (*--p == ':') break; /* s p e * SectionXXX:YY: in 'blabla' */ *e = '\0'; strncpy(line, *p ? p+1 : p, sizeof(line)); line[sizeof(line)-1] = '\0'; *e = ':'; e = p; /* s e * SectionXXX:YY: in 'blabla' */ *e = '\0'; strncpy(&file[0], s, file.size()); *e = ':'; /* Shrink to fit */ file.resize(strlen(file.c_str())); file = btData.scriptNames.value(file, file); std::string ms(640, '\0'); snprintf(&ms[0], ms.size(), "Script '%s' line %s: %s occured.\n\n%s", file.c_str(), line, RSTRING_PTR(name), RSTRING_PTR(msg)); showMsg(ms); }
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; }
static void oldbt_print_to(void *data, VALUE file, int lineno, VALUE name) { VALUE output = (VALUE)data; VALUE str = rb_sprintf("\tfrom %"PRIsVALUE":%d:in ", file, lineno); if (NIL_P(name)) { rb_str_cat2(str, "unknown method\n"); } else { rb_str_catf(str, " `%"PRIsVALUE"'\n", name); } rb_io_write(output, str); }
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); }
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; }
void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...) { VALUE mesg; va_list args; int errno_save; errno_save = errno; if (!RTEST(ruby_verbose)) return; va_start(args, fmt); mesg = warning_string(enc, fmt, args); va_end(args); rb_str_set_len(mesg, RSTRING_LEN(mesg)-1); rb_str_catf(mesg, ": %s\n", strerror(errno_save)); rb_write_error_str(mesg); errno = errno_save; }
/** * Return CLIPS fragment of code representing the constraint object. * Unfortunatelly the code don't have to be valid - the validity is not check * in this class, becuase constraint are not saved to CLIPS, so their are * checked when used. */ VALUE cl_constraint_to_s(VALUE self) { VALUE ret = rb_str_new2(""); // @type VALUE v = rb_iv_get(self, "@type"); if(!NIL_P(v)) { rb_str_cat2(ret, "(type "); long len = RARRAY_LEN(v); int i; for(i = 0; i < len; i++) rb_str_catf(ret, "%s ", rb_generic_clipstype_str( rb_to_id( rb_ary_entry(v, i ) ) ) ); rb_str_cat2(ret, ") "); } // @values v = rb_iv_get(self, "@values"); if(!NIL_P(v)) { rb_str_cat2(ret, "(values "); long len = RARRAY_LEN(v); int i; for(i = 0; i < len; i++) { VALUE entry = rb_ary_entry(v, i); if(TYPE(entry) == T_STRING) { rb_str_catf(ret, "\"%s\" ", STR2CSTR( entry ) ); } else { rb_str_catf(ret, "%s ", CL_STR(entry) ); } } rb_str_cat2(ret, ") "); } // @range v = rb_iv_get(self, "@range"); if(!NIL_P(v)) { VALUE begin = rb_funcall(v, cl_vIds.begin, 0); VALUE end = rb_funcall(v, cl_vIds.end, 0); long lbegin = NUM2LONG(begin); long lend = NUM2LONG(end); rb_str_catf(ret, "(range %lu %lu) ", lbegin, lend ); } // @cardinality v = rb_iv_get(self, "@cardinality"); if(!NIL_P(v)) { VALUE begin = rb_funcall(v, cl_vIds.begin, 0); VALUE end = rb_funcall(v, cl_vIds.end, 0); long lbegin = NUM2LONG(begin); long lend = NUM2LONG(end); rb_str_catf(ret, "(cardinality %lu %lu) ", lbegin, lend ); } // C'est tout return ret; }