10 #define TKUTIL_RELEASE_DATE "2010-03-26"
15 static VALUE rb_thread_critical;
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
123 #ifdef HAVE_RB_OBJ_TAINT
126 #ifdef HAVE_RB_OBJ_UNTRUST
139 volatile VALUE cmd, rest;
169 volatile VALUE id_num;
205 int head_len =
strlen(cmd_id_head);
206 int prefix_len =
strlen(cmd_id_prefix);
209 if (strncmp(cmd_id_head,
RSTRING_PTR(cmd_id), head_len) != 0) {
212 if (strncmp(cmd_id_prefix,
213 RSTRING_PTR(cmd_id) + head_len, prefix_len) != 0) {
252 fromUTF8_toDefaultEnc(str,
self)
281 if NIL_P(keys)
return new_keys;
301 int idx, idx2,
size, size2, req_chk_flag;
302 volatile VALUE val, val2, str_val;
304 volatile VALUE sys_enc, dst_enc, str_enc;
307 if (
NIL_P(sys_enc)) {
339 str_val =
ary2list(val, enc_flag,
self);
344 if (!
NIL_P(str_enc)) {
359 if (
RTEST(enc_flag)) {
365 for(idx2 = 0; idx2 < size2; idx2++) {
369 str_val =
ary2list(val2, enc_flag,
self);
374 if (
RTEST(enc_flag)) {
391 if (!
NIL_P(str_enc)) {
411 if (!
NIL_P(str_enc)) {
454 int idx,
size, req_chk_flag;
455 volatile VALUE val, str_val;
457 volatile VALUE sys_enc, dst_enc, str_enc;
483 str_val =
ary2list(val, enc_flag,
self);
487 if (
RTEST(enc_flag)) {
500 if (!
NIL_P(str_val)) {
505 if (!
NIL_P(str_enc)) {
561 for(i = 0; i <
len; i++) {
609 for(i = 0; i <
len; i++) {
774 if (
RTEST(enc_flag)) {
781 if (
RTEST(enc_flag)) {
784 return hash2kv(hash, ary,
self);
819 if (
RTEST(enc_flag)) {
830 if (
RTEST(enc_flag)) {
838 #ifdef HAVE_RB_SYM_TO_S
846 if (
RTEST(enc_flag)) {
853 return ary2list(obj, enc_flag,
self);
899 rb_warning(
"fail to convert '%s' to string for Tk",
911 volatile VALUE obj, enc_flag;
913 if (
rb_scan_args(argc, argv,
"11", &obj, &enc_flag) == 1) {
947 thr_crit_bup = rb_thread_critical;
948 rb_thread_critical =
Qtrue;
951 for(size = 0, idx = 2; idx <
argc; idx++) {
960 for(idx = 2; idx <
argc; idx++) {
962 if (
RTEST(argv[1])) {
967 }
else if (argv[idx] !=
TK_None) {
973 rb_thread_critical = thr_crit_bup;
1043 "invalid value for Number: '%s'",
RSTRING_PTR(value));
1087 if (len > 1 && *ptr ==
'{' && *(ptr + len - 1) ==
'}') {
1134 #define CBSUBST_TBL_MAX (256)
1161 if (ptr->key[i] !=
NULL) {
1184 inf->
type[idx] =
'\0';
1220 if ( inf->
ivar[iv_idx] == (
ID) 0 )
continue;
1222 if (idx >= argc)
break;
1243 ID key_id, value_id;
1256 "includes invalid key(s). expected a String or a Symbol");
1259 switch(
TYPE(value)) {
1264 value_id =
SYM2ID(value);
1268 "includes invalid value(s). expected a String or a Symbol");
1321 if (inf->
ivar[idx] ==
id)
break;
1323 if (idx >= CBSUBST_TBL_MAX)
return sym;
1329 if (len = inf->
keylen[idx]) {
1331 strncpy(ptr, inf->
key[idx], len);
1335 *(ptr++) = (
unsigned char)idx;
1359 volatile VALUE arg_sym, ret;
1366 for(i = 0; i <
argc; i++) {
1367 switch(
TYPE(argv[i])) {
1387 if (inf->
ivar[idx] ==
id)
break;
1389 if (idx >= CBSUBST_TBL_MAX) {
1395 if (len = inf->
keylen[idx]) {
1397 strncpy(ptr, inf->
key[idx], len);
1401 *(ptr++) = (
unsigned char)idx;
1436 for(i = 0; i <
len; i++) {
1440 if (*(key + 2) ==
'\0') {
1442 *(ptr++) = *(key + 1);
1447 if (inf->
keylen[idx] != keylen)
continue;
1448 if ((
unsigned char)inf->
key[idx][0] != (
unsigned char)*(key + 1))
continue;
1449 if (strncmp(inf->
key[idx], key + 1, keylen))
continue;
1452 if (idx < CBSUBST_TBL_MAX) {
1453 *(ptr++) = (
unsigned char)idx;
1475 char *keys_buf, *keys_ptr;
1486 if (inf->
ivar[idx] == (
ID) 0)
continue;
1488 *(keys_ptr++) = (
unsigned char)idx;
1492 if (len = inf->
keylen[idx]) {
1494 strncpy(ptr, inf->
key[idx], len);
1498 *(ptr++) = (
unsigned char)idx;
1521 volatile VALUE cbsubst_obj;
1522 volatile VALUE key_inf;
1523 volatile VALUE longkey_inf;
1524 volatile VALUE proc_inf;
1532 if (
rb_scan_args(argc, argv,
"21", &key_inf, &longkey_inf, &proc_inf) == 2) {
1533 proc_inf = longkey_inf;
1552 for(idx = 0; idx <
len; idx++) {
1583 for(idx = 0; idx <
len; idx++) {
1587 chr = (
unsigned char)(0x80 + idx);
1594 if (subst_inf->
key[chr]) {
1620 for(idx = 0; idx <
len; idx++) {
1650 unsigned char *keyptr = (
unsigned char*)
RSTRING_PTR(arg_key);
1653 unsigned char type_chr;
1659 thr_crit_bup = rb_thread_critical;
1660 rb_thread_critical =
Qtrue;
1667 for(idx = 0; idx < vallen; idx++) {
1668 if (idx >= keylen) {
1670 }
else if (*(keyptr + idx) ==
' ') {
1673 if (type_chr = inf->
type[*(keyptr + idx)]) {
1689 rb_thread_critical = thr_crit_bup;