10 #define TKUTIL_RELEASE_DATE "2010-03-26"
26 #if !defined(RHASH_TBL)
27 #define RHASH_TBL(h) (RHASH(h)->tbl)
29 #if !defined(RSTRING_PTR)
30 #define RSTRING_PTR(s) (RSTRING(s)->ptr)
31 #define RSTRING_LEN(s) (RSTRING(s)->len)
33 #if !defined(RARRAY_PTR)
34 #define RARRAY_PTR(s) (RARRAY(s)->ptr)
35 #define RARRAY_LEN(s) (RARRAY(s)->len)
38 #if defined(HAVE_STRNDUP) && !defined(_GNU_SOURCE)
39 extern char *strndup(
const char* _ptr,
size_t _len);
79 #if defined(HAVE_RB_OBJ_INSTANCE_EXEC) && !defined(RUBY_VM)
91 #ifndef HAVE_RB_OBJ_INSTANCE_EXEC
119 tk_obj_untrust(
self, obj)
123 #ifdef HAVE_RB_OBJ_TAINT
126 #ifdef HAVE_RB_OBJ_UNTRUST
134 tk_eval_cmd(argc, argv,
self)
146 tk_do_callback(argc, argv,
self)
179 tk_install_cmd(argc, argv,
self)
201 tk_uninstall_cmd(
self,
cmd_id)
205 size_t head_len =
strlen(cmd_id_head);
212 if (strncmp(cmd_id_prefix,
213 RSTRING_PTR(cmd_id) + head_len, prefix_len) != 0) {
231 tk_fromUTF8(argc, argv,
self)
240 fromDefaultEnc_toUTF8(
str,
self)
252 fromUTF8_toDefaultEnc(
str,
self)
259 return tk_fromUTF8(1, argv,
self);
274 tk_symbolkey2str(
self,
keys)
307 if (
NIL_P(sys_enc)) {
312 if (
NIL_P(enc_flag)) {
339 str_val = ary2list(val, enc_flag,
self);
344 if (!
NIL_P(str_enc)) {
359 if (
RTEST(enc_flag)) {
360 val = hash2kv_enc(val,
Qnil,
self);
362 val = hash2kv(val,
Qnil,
self);
365 for(idx2 = 0; idx2 < size2; idx2++) {
369 str_val = ary2list(val2, enc_flag,
self);
374 if (
RTEST(enc_flag)) {
375 str_val = hash2list_enc(val2,
self);
377 str_val = hash2list(val2,
self);
391 if (!
NIL_P(str_enc)) {
411 if (!
NIL_P(str_enc)) {
449 ary2list2(ary, enc_flag,
self)
484 str_val = ary2list(val, enc_flag,
self);
488 if (
RTEST(enc_flag)) {
489 str_val = hash2list(val,
self);
491 str_val = hash2list_enc(val,
self);
501 if (!
NIL_P(str_val)) {
506 if (!
NIL_P(str_enc)) {
550 assoc2kv(
assoc, ary,
self)
562 for(i = 0; i <
len; i++) {
598 assoc2kv_enc(assoc, ary,
self)
610 for(i = 0; i <
len; i++) {
669 hash2kv(
hash, ary,
self)
687 push_kv_enc(key, val, args)
713 hash2kv_enc(hash, ary,
self)
731 hash2list(hash,
self)
735 return ary2list2(hash2kv(hash,
Qnil,
self),
Qfalse,
self);
740 hash2list_enc(hash,
self)
744 return ary2list2(hash2kv_enc(hash,
Qnil,
self),
Qfalse,
self);
748 tk_hash_kv(argc, argv,
self)
773 if (
RTEST(enc_flag)) {
774 return assoc2kv_enc(hash, ary,
self);
776 return assoc2kv(hash, ary,
self);
780 if (
RTEST(enc_flag)) {
781 return hash2kv_enc(hash, ary,
self);
783 return hash2kv(hash, ary,
self);
820 if (
RTEST(enc_flag)) {
824 return fromDefaultEnc_toUTF8(obj,
self);
831 if (
RTEST(enc_flag)) {
839 #ifdef HAVE_RB_SYM_TO_S
847 if (
RTEST(enc_flag)) {
848 return hash2list_enc(obj,
self);
850 return hash2list(obj,
self);
854 return ary2list(obj, enc_flag,
self);
900 rb_warning(
"fail to convert '%s' to string for Tk",
907 tk_get_eval_string(argc, argv,
self)
922 tk_get_eval_enc_str(
self, obj)
934 tk_conv_args(argc, argv,
self)
952 for(size = 0, idx = 2; idx <
argc; idx++) {
961 for(idx = 2; idx <
argc; idx++) {
963 if (
RTEST(argv[1])) {
964 hash2kv_enc(argv[idx], dst,
self);
966 hash2kv(argv[idx], dst,
self);
968 }
else if (argv[idx] !=
TK_None) {
983 tcl2rb_bool(
self,
value)
1033 tkstr_to_float(value)
1040 tkstr_invalid_numstr(value)
1044 "invalid value for Number: '%s'",
RSTRING_PTR(value));
1049 tkstr_rescue_float(value)
1053 tkstr_invalid_numstr, value,
1058 tkstr_to_number(value)
1066 tkstr_rescue_float, value,
1071 tcl2rb_number(
self, value)
1075 return tkstr_to_number(value);
1088 if (len > 1 && *ptr ==
'{' && *(ptr + len - 1) ==
'}') {
1095 tcl2rb_string(
self, value)
1103 return tkstr_to_str(value);
1107 tcl2rb_num_or_str(
self, value)
1116 tkstr_to_str, value,
1121 tcl2rb_num_or_nil(
self, value)
1129 return tkstr_to_number(value);
1135 #define CBSUBST_TBL_MAX (256)
1136 struct cbsubst_info {
1137 long full_subst_length;
1148 struct cbsubst_info *ptr;
1156 struct cbsubst_info *ptr;
1162 if (ptr->key[i] !=
NULL) {
1174 struct cbsubst_info *
inf;
1178 inf =
ALLOC(
struct cbsubst_info);
1180 inf->full_subst_length = 0;
1183 inf->keylen[
idx] = 0;
1185 inf->type[
idx] =
'\0';
1186 inf->ivar[
idx] = (
ID) 0;
1193 inf->aliases = aliases;
1195 if (inf_ptr != (
struct cbsubst_info **)
NULL) *inf_ptr =
inf;
1208 cbsubst_initialize(argc, argv,
self)
1213 struct cbsubst_info *
inf;
1217 struct cbsubst_info, inf);
1221 if ( inf->ivar[iv_idx] == (
ID) 0 )
continue;
1222 rb_ivar_set(
self, inf->ivar[iv_idx], argv[idx++]);
1223 if (idx >= argc)
break;
1230 cbsubst_ret_val(
self, val)
1241 each_attr_def(key, value, klass)
1242 VALUE key, value, klass;
1244 ID key_id, value_id;
1257 "includes invalid key(s). expected a String or a Symbol");
1265 value_id =
SYM2ID(value);
1269 "includes invalid value(s). expected a String or a Symbol");
1278 cbsubst_def_attr_aliases(
self,
tbl)
1282 struct cbsubst_info *
inf;
1289 struct cbsubst_info, inf);
1297 cbsubst_sym_to_subst(
self,
sym)
1301 struct cbsubst_info *
inf;
1312 struct cbsubst_info, inf);
1323 if (inf->ivar[idx] ==
id)
break;
1325 if (idx >= CBSUBST_TBL_MAX)
return sym;
1327 ptr = buf =
ALLOC_N(
char, inf->full_subst_length + 1);
1331 if (len = inf->keylen[idx]) {
1333 strncpy(ptr, inf->key[idx], len);
1337 *(ptr++) = (
unsigned char)
idx;
1351 cbsubst_get_subst_arg(argc, argv,
self)
1356 struct cbsubst_info *
inf;
1365 struct cbsubst_info, inf);
1367 ptr = buf =
ALLOC_N(
char, inf->full_subst_length + 1);
1369 for(i = 0; i <
argc; i++) {
1370 switch(
TYPE(argv[i])) {
1390 if (inf->ivar[idx] ==
id)
break;
1392 if (idx >= CBSUBST_TBL_MAX) {
1398 if (len = inf->keylen[idx]) {
1400 strncpy(ptr, inf->key[idx], len);
1404 *(ptr++) = (
unsigned char)
idx;
1420 cbsubst_get_subst_key(
self, str)
1424 struct cbsubst_info *
inf;
1436 struct cbsubst_info, inf);
1438 ptr = buf =
ALLOC_N(
char, inf->full_subst_length + len + 1);
1440 for(i = 0; i <
len; i++) {
1444 if (*(key + 2) ==
'\0') {
1446 *(ptr++) = *(key + 1);
1451 if (inf->keylen[idx] != keylen)
continue;
1452 if ((
unsigned char)inf->key[idx][0] != (
unsigned char)*(key + 1))
continue;
1453 if (strncmp(inf->key[idx], key + 1, keylen))
continue;
1456 if (idx < CBSUBST_TBL_MAX) {
1457 *(ptr++) = (
unsigned char)
idx;
1474 cbsubst_get_all_subst_keys(
self)
1477 struct cbsubst_info *
inf;
1485 struct cbsubst_info, inf);
1487 ptr = buf =
ALLOC_N(
char, inf->full_subst_length + 1);
1488 keys_ptr = keys_buf =
ALLOC_N(
char, CBSUBST_TBL_MAX + 1);
1491 if (inf->ivar[idx] == (
ID) 0)
continue;
1493 *(keys_ptr++) = (
unsigned char)
idx;
1497 if (len = inf->keylen[idx]) {
1499 strncpy(ptr, inf->key[idx], len);
1503 *(ptr++) = (
unsigned char)
idx;
1521 cbsubst_table_setup(argc, argv,
self)
1537 if (
rb_scan_args(argc, argv,
"21", &key_inf, &longkey_inf, &proc_inf) == 2) {
1557 for(idx = 0; idx <
len; idx++) {
1572 subst_inf->full_subst_length += 3;
1588 for(idx = 0; idx <
len; idx++) {
1592 chr = (
unsigned char)(0x80 + idx);
1599 if (subst_inf->key[chr]) {
1611 subst_inf->full_subst_length += (subst_inf->keylen[
chr] + 2);
1625 for(idx = 0; idx <
len; idx++) {
1641 cbsubst_get_extra_args_tbl(
self)
1653 struct cbsubst_info *
inf;
1670 struct cbsubst_info, inf);
1672 for(idx = 0; idx <
vallen; idx++) {
1673 if (idx >= keylen) {
1675 }
else if (*(keyptr + idx) ==
' ') {
1678 if (type_chr = inf->type[*(keyptr + idx)]) {
1700 cbsubst_inspect(
self)
1707 substinfo_inspect(
self)
1716 tk_cbe_inspect(
self)
1775 cbsubst_sym_to_subst, 1);
1777 cbsubst_get_subst_arg, -1);
1779 cbsubst_get_subst_key, 1);
1781 cbsubst_get_all_subst_keys, 0);
1783 cbsubst_table_setup, -1);
1785 cbsubst_get_extra_args_tbl, 0);
1787 cbsubst_def_attr_aliases, 1);
1836 tk_get_eval_string, -1);
1838 tk_get_eval_enc_str, 1);
VALUE rb_gc_disable(void)
return tk_toUTF8(1, argv, self)
VALUE rb_obj_instance_exec(int, VALUE *, VALUE)
size_t strlen(const char *)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
static ID ID_encoding_system
VALUE rb_eval_cmd(VALUE, VALUE, int)
#define rb_tainted_str_new2
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static int rb_thread_critical
double rb_cstr_to_dbl(const char *, int)
VALUE rb_const_get(VALUE, ID)
int rb_str_cmp(VALUE, VALUE)
VALUE rb_obj_freeze(VALUE)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_require(const char *)
static const char cmd_id_head[]
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
static const char cmd_id_prefix[]
VALUE rb_obj_class(VALUE)
static ID ID_merge_tklist
VALUE rb_ary_new3(long n,...)
VALUE rb_str_append(VALUE, VALUE)
VALUE rb_ivar_get(VALUE, ID)
void rb_hash_foreach(VALUE, int(*)(ANYARGS), VALUE)
VALUE rb_hash_delete(VALUE, VALUE)
VALUE rb_obj_instance_eval(int, VALUE *, VALUE)
static VALUE rb_float_new(double d)
VALUE rb_block_proc(void)
return Data_Wrap_Struct(CLASS_OF(interp), 0, ip_free, slave)
VALUE rb_obj_untrust(VALUE)
int rb_block_given_p(void)
static ID ID_split_tklist
static VALUE CALLBACK_TABLE
void rb_define_const(VALUE, const char *, VALUE)
const char tkutil_release_date[]
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_check_type(VALUE x, int t)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
static VALUE cTkCallbackEntry
static unsigned long CALLBACK_ID_NUM
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static void cbsubst_init()
void rb_attr(VALUE, ID, int, int, int)
void rb_const_set(VALUE, ID, VALUE)
void rb_alias(VALUE, ID, ID)
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
return tk_install_cmd_core(cmd)
VALUE rb_obj_taint(VALUE)
VALUE rb_ivar_set(VALUE, ID, VALUE)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
VALUE rb_ary_plus(VALUE x, VALUE y)
static VALUE ENCODING_NAME_UTF8
int rb_obj_respond_to(VALUE, ID, int)
RUBY_EXTERN VALUE rb_cObject
struct rb_encoding_entry * list
#define Data_Get_Struct(obj, type, sval)
VALUE rb_apply(VALUE, ID, VALUE)
Calls a method.
VALUE rb_ary_concat(VALUE x, VALUE y)
VALUE rb_ary_new2(long capa)
int st_foreach_check(st_table *, int(*)(ANYARGS), st_data_t, st_data_t)
VALUE rb_str_new(const char *, long)
RUBY_EXTERN VALUE rb_cProc
volatile VALUE longkey_inf
VALUE rb_obj_alloc(VALUE)
const char * rb_id2name(ID id)
void rb_global_variable(VALUE *)
#define TKUTIL_RELEASE_DATE
VALUE rb_hash_aref(VALUE, VALUE)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
void rb_warning(const char *fmt,...)
static VALUE allocate_cbsubst_info(struct cbsubst_info **inf_ptr)
struct cbsubst_info * subst_inf
VALUE rb_define_module(const char *name)
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
return get_eval_string_core(obj, enc_flag, self)
VALUE rb_convert_type(VALUE, int, const char *, const char *)