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
123 #ifdef HAVE_RB_OBJ_TAINT
126 #ifdef HAVE_RB_OBJ_UNTRUST
139 volatile VALUE cmd, rest;
169 volatile VALUE id_num;
205 size_t head_len =
strlen(cmd_id_head);
206 size_t 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)
280 if (
NIL_P(keys))
return new_keys;
300 long idx, idx2,
size, size2;
304 volatile VALUE sys_enc, dst_enc, str_enc;
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)) {
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)) {
458 volatile VALUE sys_enc, dst_enc, str_enc;
461 if (
NIL_P(sys_enc)) {
466 if (
NIL_P(enc_flag)) {
484 str_val =
ary2list(val, enc_flag,
self);
488 if (
RTEST(enc_flag)) {
501 if (!
NIL_P(str_val)) {
506 if (!
NIL_P(str_enc)) {
562 for(i = 0; i < len; i++) {
610 for(i = 0; i < len; i++) {
773 if (
RTEST(enc_flag)) {
780 if (
RTEST(enc_flag)) {
783 return hash2kv(hash, ary,
self);
820 if (
RTEST(enc_flag)) {
831 if (
RTEST(enc_flag)) {
839 #ifdef HAVE_RB_SYM_TO_S
847 if (
RTEST(enc_flag)) {
854 return ary2list(obj, enc_flag,
self);
900 rb_warning(
"fail to convert '%s' to string for Tk",
912 volatile VALUE obj, enc_flag;
914 if (
rb_scan_args(argc, argv,
"11", &obj, &enc_flag) == 1) {
952 for(size = 0, idx = 2; idx <
argc; idx++) {
961 for(idx = 2; idx <
argc; idx++) {
963 if (
RTEST(argv[1])) {
968 }
else if (argv[idx] !=
TK_None) {
1044 "invalid value for Number: '%s'",
RSTRING_PTR(value));
1088 if (len > 1 && *ptr ==
'{' && *(ptr + len - 1) ==
'}') {
1135 #define CBSUBST_TBL_MAX (256)
1162 if (ptr->key[i] !=
NULL) {
1185 inf->
type[idx] =
'\0';
1221 if ( inf->
ivar[iv_idx] == (
ID) 0 )
continue;
1223 if (idx >= argc)
break;
1244 ID key_id, value_id;
1257 "includes invalid key(s). expected a String or a Symbol");
1260 switch(
TYPE(value)) {
1265 value_id =
SYM2ID(value);
1269 "includes invalid value(s). expected a String or a Symbol");
1323 if (inf->
ivar[idx] ==
id)
break;
1325 if (idx >= CBSUBST_TBL_MAX)
return sym;
1331 if (len = inf->
keylen[idx]) {
1333 strncpy(ptr, inf->
key[idx], len);
1337 *(ptr++) = (
unsigned char)idx;
1362 volatile VALUE arg_sym, ret;
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;
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;
1479 char *keys_buf, *keys_ptr;
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;
1526 volatile VALUE cbsubst_obj;
1527 volatile VALUE key_inf;
1528 volatile VALUE longkey_inf;
1529 volatile VALUE proc_inf;
1537 if (
rb_scan_args(argc, argv,
"21", &key_inf, &longkey_inf, &proc_inf) == 2) {
1538 proc_inf = longkey_inf;
1557 for(idx = 0; idx < len; idx++) {
1588 for(idx = 0; idx < len; idx++) {
1592 chr = (
unsigned char)(0x80 + idx);
1599 if (subst_inf->
key[chr]) {
1625 for(idx = 0; idx < len; idx++) {
1655 unsigned char *keyptr = (
unsigned char*)
RSTRING_PTR(arg_key);
1658 unsigned char type_chr;
1672 for(idx = 0; idx < vallen; idx++) {
1673 if (idx >= keylen) {
1675 }
else if (*(keyptr + idx) ==
' ') {
1678 if (type_chr = inf->
type[*(keyptr + idx)]) {
VALUE rb_apply(VALUE, ID, VALUE)
Calls a method.
static VALUE get_eval_string_core(VALUE obj, VALUE enc_flag, VALUE self)
static VALUE hash2kv_enc(VALUE hash, VALUE ary, VALUE self)
static int push_kv_enc(VALUE key, VALUE val, VALUE args)
size_t strlen(const char *)
static ID ID_encoding_system
#define Data_Get_Struct(obj, type, sval)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static VALUE fromDefaultEnc_toUTF8(VALUE str, VALUE self)
static VALUE hash2list_enc(VALUE hash, VALUE self)
static VALUE rb_float_new(double d)
VALUE rb_ary_push(VALUE ary, VALUE item)
static VALUE hash2kv(VALUE hash, VALUE ary, VALUE self)
static const char cmd_id_head[]
static VALUE cbsubst_get_subst_key(VALUE self, VALUE str)
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,...)
VALUE rb_ivar_get(VALUE, ID)
static const char cmd_id_prefix[]
static VALUE tk_toUTF8(int argc, VALUE *argv, VALUE self)
static ID ID_merge_tklist
VALUE rb_convert_type(VALUE, int, const char *, const char *)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
VALUE rb_tainted_str_new2(const char *)
VALUE rb_ary_new3(long n,...)
static VALUE tkstr_to_str(VALUE value)
void rb_gc_mark(VALUE ptr)
static VALUE cbsubst_sym_to_subst(VALUE self, VALUE sym)
int rb_str_cmp(VALUE, VALUE)
RUBY_EXTERN VALUE rb_cProc
static VALUE tkstr_to_float(VALUE value)
static VALUE tk_symbolkey2str(VALUE self, VALUE keys)
VALUE rb_obj_untrust(VALUE)
static VALUE tk_uninstall_cmd(VALUE self, VALUE cmd_id)
static VALUE tcl2rb_string(VALUE self, VALUE value)
#define Data_Wrap_Struct(klass, mark, free, sval)
void rb_global_variable(VALUE *var)
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
static VALUE assoc2kv(VALUE assoc, VALUE ary, VALUE self)
static VALUE tk_hash_kv(int argc, VALUE *argv, VALUE self)
VALUE rb_require(const char *)
static VALUE ary2list2(VALUE ary, VALUE enc_flag, VALUE self)
static VALUE tkstr_to_int(VALUE value)
static VALUE tkNone_to_s(VALUE self)
static VALUE tk_fromUTF8(int argc, VALUE *argv, VALUE self)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
static VALUE assoc2kv_enc(VALUE assoc, VALUE ary, VALUE self)
int rb_block_given_p(void)
VALUE rb_obj_taint(VALUE)
RUBY_EXTERN VALUE rb_cObject
void rb_attr(VALUE, ID, int, int, int)
static ID ID_split_tklist
VALUE rb_str_cat2(VALUE, const char *)
static VALUE CALLBACK_TABLE
const char tkutil_release_date[]
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_define_const(VALUE, const char *, VALUE)
static int to_strkey(VALUE key, VALUE value, VALUE hash)
void rb_check_type(VALUE x, int t)
VALUE rb_obj_alloc(VALUE)
static VALUE substinfo_inspect(VALUE self)
static VALUE tk_eval_cmd(int argc, argv, VALUE self)
VALUE rb_const_get(VALUE, ID)
static VALUE tk_s_new(int argc, VALUE *argv, VALUE klass)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
VALUE rb_hash_delete(VALUE hash, VALUE key)
static VALUE cTkCallbackEntry
int rb_obj_respond_to(VALUE, ID, int)
static unsigned long CALLBACK_ID_NUM
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static void cbsubst_init()
VALUE rb_ivar_set(VALUE, ID, VALUE)
unsigned char buf[MIME_BUF_SIZE]
static VALUE tkobj_path(VALUE self)
static VALUE cbsubst_get_all_subst_keys(VALUE self)
void rb_const_set(VALUE, ID, VALUE)
static int rb_thread_critical
static VALUE cbsubst_get_extra_args_tbl(VALUE self)
void rb_alias(VALUE, ID, ID)
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
static VALUE tk_obj_untrust(VALUE self, VALUE obj)
VALUE rb_gc_disable(void)
static VALUE cbsubst_initialize(int argc, VALUE *argv, VALUE self)
static VALUE cbsubst_table_setup(int argc, VALUE *argv, VALUE self)
static VALUE tkstr_invalid_numstr(VALUE value)
static VALUE tk_get_eval_string(int argc, VALUE *argv, VALUE self)
static VALUE cbsubst_scan_args(VALUE self, VALUE arg_key, VALUE val_ary)
static void subst_mark(struct cbsubst_info *ptr)
VALUE rb_block_proc(void)
long keylen[CBSUBST_TBL_MAX]
VALUE rb_ary_plus(VALUE x, VALUE y)
static VALUE tcl2rb_bool(VALUE self, VALUE value)
VALUE rb_hash_aref(VALUE hash, VALUE key)
static VALUE ENCODING_NAME_UTF8
static int push_kv(VALUE key, VALUE val, VALUE args)
static VALUE cbsubst_ret_val(VALUE self, VALUE val)
static VALUE tk_install_cmd_core(VALUE cmd)
char * key[CBSUBST_TBL_MAX]
static VALUE tk_install_cmd(int argc, VALUE *argv, VALUE self)
static VALUE tk_cbe_inspect(VALUE self)
int st_foreach_check(st_table *, int(*)(ANYARGS), st_data_t, st_data_t)
struct rb_encoding_entry * list
static VALUE tkNone_inspect(VALUE self)
static VALUE cbsubst_inspect(VALUE self)
char type[CBSUBST_TBL_MAX]
VALUE rb_eval_cmd(VALUE, VALUE, int)
VALUE rb_ary_concat(VALUE x, VALUE y)
static unsigned int hash(const char *str, unsigned int len)
VALUE rb_ary_new2(long capa)
const char * rb_id2name(ID id)
VALUE rb_obj_instance_exec(int, VALUE *, VALUE)
VALUE rb_obj_instance_eval(int, VALUE *, VALUE)
#define TKUTIL_RELEASE_DATE
static VALUE tcl2rb_num_or_str(VALUE self, VALUE value)
void rb_warning(const char *fmt,...)
static VALUE allocate_cbsubst_info(struct cbsubst_info **inf_ptr)
static int each_attr_def(VALUE key, VALUE value, VALUE klass)
static VALUE tcl2rb_num_or_nil(VALUE self, VALUE value)
static VALUE tkstr_rescue_float(VALUE value)
VALUE rb_obj_freeze(VALUE)
static VALUE get_eval_string_core _((VALUE, VALUE, VALUE))
static VALUE key2keyname(VALUE key)
VALUE rb_define_module(const char *name)
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
static VALUE tk_get_eval_enc_str(VALUE self, VALUE obj)
static VALUE cbsubst_def_attr_aliases(VALUE self, VALUE tbl)
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
static VALUE tcl2rb_number(VALUE self, VALUE value)
static VALUE ary2list(VALUE ary, VALUE enc_flag, VALUE self)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
VALUE rb_str_new2(const char *)
static VALUE cbsubst_get_subst_arg(int argc, VALUE *argv, VALUE self)
double rb_cstr_to_dbl(const char *, int)
static void subst_free(struct cbsubst_info *ptr)
static VALUE tkstr_to_number(VALUE value)
static VALUE tk_conv_args(int argc, VALUE *argv, VALUE self)
static VALUE hash2list(VALUE hash, VALUE self)
static VALUE tk_do_callback(int argc, VALUE *argv, VALUE self)
VALUE rb_obj_class(VALUE)
VALUE rb_str_new(const char *, long)