X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fconcord.git;a=blobdiff_plain;f=cos.c;h=5df8af21bf99b34c7801246bbe7cad803f7a6dcd;hp=546078c1aa800041d89fd52333e1c61c6b06f146;hb=e99e93e4773c5f3472b088db2659f7a848cbcc21;hpb=9d5ac7dd218b16b424b3bc9af323e2f4725978ce diff --git a/cos.c b/cos.c index 546078c..5df8af2 100644 --- a/cos.c +++ b/cos.c @@ -98,7 +98,7 @@ int cos_char_id (COS_object obj) { if (COS_OBJECT_CHAR_P (obj)) - return ((COS_INT)obj) >> 2; + return (((COS_INT)obj) >> 2) & 0x7FFFFFFF; return -1; } @@ -136,12 +136,12 @@ cos_release_object (COS_object obj) { if (COS_OBJECT_P (obj)) { - ((COS_Object)obj)->header.reference_count--; - if ( ((COS_Object)obj)->header.reference_count <= 0 ) return (*COS_Object_release_function_table [((COS_Object)obj)->header.type - COS_FAT_OBJECT_TYPE_MIN])(obj); + else + ((COS_Object)obj)->header.reference_count--; } return 0; } @@ -248,8 +248,8 @@ cos_cons (COS_object car, COS_object cdr) int cos_retain_cons (COS_Object obj) { - cos_retain_object (COS_CAR (obj)); - cos_retain_object (COS_CDR (obj)); + //cos_retain_object (COS_CAR (obj)); + //cos_retain_object (COS_CDR (obj)); return 0; } @@ -289,6 +289,29 @@ cos_cdr (COS_Cons pair) return NULL; } +COS_Cons +cos_assoc (COS_object key, COS_Cons alist) +{ + COS_Cons rest = alist; + + while ( COS_OBJECT_CONS_P (rest) ) + { + COS_Cons cell = cos_car (rest); + + if ( cos_car (cell) == key ) + return cell; + + rest = cos_cdr (rest); + } + return NULL; +} + +COS_object +cos_alist_get (COS_Cons alist, COS_object key) +{ + return cos_cdr (cos_assoc (key, alist)); +} + int cos_retain_container (COS_Object obj) @@ -363,6 +386,12 @@ cos_release_ds (COS_Object obj) return concord_close_ds ((COS_DS)obj); } +int +concord_ds_p (COS_object obj) +{ + return COS_OBJECT_DS_P (obj); +} + COS_Genre concord_get_genre (COS_object ds, COS_object genre) @@ -480,67 +509,47 @@ concord_decode_object (COS_object ds, COS_object genre, char* id_str; char buf[256]; CONCORD_String_Tank obj_st; - COS_String obj_string; int cid; size_t end; if (index == NULL) return NULL; - printf ("decoding id (%lX)...", id); if (COS_OBJECT_INT_P (id)) { - printf ("(id is an int)..."); snprintf(buf, 256, "%ld", cos_int_value (id)); id_str = buf; } else if (COS_OBJECT_CHAR_P (id)) { - printf ("(id is a char)..."); - snprintf(buf, 256, "%ld", cos_char_id (id)); + snprintf(buf, 256, "%d", cos_char_id (id)); id_str = buf; } else if (COS_OBJECT_SYMBOL_P (id)) { - printf ("(id is a symbol)...."); id_str = cos_string_data (cos_symbol_name ((COS_Symbol)id)); } else if (COS_OBJECT_C_STRING_P (id)) { - printf ("(id is a C-string)...."); id_str = (char*)id; } else if (COS_OBJECT_STRING_P (id)) { - printf ("(id is a string)...."); id_str = cos_string_data ((COS_String)id); } else return NULL; - printf ("done (%s).\n", id_str); if ( concord_index_strid_get_obj_string (index, id_str, &obj_st) ) return NULL; - obj_string = cos_make_string ((char*)CONCORD_String_data (&obj_st), - CONCORD_String_size (&obj_st)); - cid = cos_read_char (CONCORD_String_data (&obj_st), CONCORD_String_size (&obj_st), 0, &end); if ( cid >= 0 ) { - printf ("obj = %s (%d, U+%04X), len = %d, end = %d\n", - cos_string_data (obj_string), - cid, cid, - CONCORD_String_size (&obj_st), end); - cos_release_object (obj_string); return cos_make_char (cid); } - else - printf ("obj = %s\n", cos_string_data (obj_string)); - - cos_release_object (obj_string); return NULL; } @@ -549,34 +558,35 @@ COS_object concord_object_get_feature_value (COS_object object, COS_object feature) { char id_buf[256]; + CONCORD_Genre gobj; CONCORD_Feature fobj; CONCORD_String_Tank val_st; - COS_String val_string; size_t end; if (COS_OBJECT_CHAR_P (object)) { - cos_utf8_print_char (object, id_buf, 256); - printf ("Object[char:0x%lX]'s id is %s.\n", object, id_buf); + cos_utf8_print_char (object, (unsigned char*)id_buf, 256); } else return NULL; - fobj = concord_get_feature (concord_current_env, - "character", feature); + if (!COS_OBJECT_DS_P (concord_current_env)) + { + concord_current_env = NULL; + return NULL; + } + + gobj = concord_get_genre (concord_current_env, "character"); + if (gobj == NULL) + return NULL; + + fobj = concord_get_feature (concord_current_env, gobj, feature); if (fobj == NULL) return NULL; if ( concord_obj_get_feature_value_string (id_buf, fobj, &val_st) ) return NULL; - val_string = cos_make_string ((char*)CONCORD_String_data (&val_st), - CONCORD_String_size (&val_st)); - printf ("obj[%s]'s %s = %s\n", - id_buf, - concord_feature_get_name (fobj), - cos_string_data (val_string)); - return cos_read_object (CONCORD_String_data (&val_st), CONCORD_String_size (&val_st), 0, &end);