1 #ifndef SDLSKK_INTERNAL_H 2 #define SDLSKK_INTERNAL_H 3 4 #include "sdlskk.h" 5 6 #ifdef HAVE_CONFIG_H 7 #include "config.h" 8 #endif 9 10 #define DICT_TABLE_SIZE 10297 11 #define NOT_MARKED -1 12 13 #define CTRL(x) ((x)-'a'+1) 14 15 #include <string.h> 16 17 typedef struct SDLSKK_XStr SDLSKK_XStr; 18 struct SDLSKK_XStr { 19 SDLSKK_Char* buf; 20 int len; 21 int max; 22 }; 23 24 typedef struct SDLSKK_ListElement SDLSKK_ListElement; 25 struct SDLSKK_ListElement { 26 SDLSKK_ListElement *next, *prev; 27 SDLSKK_Char *val; 28 int save; 29 }; 30 31 typedef struct SDLSKK_StrList SDLSKK_StrList; 32 struct SDLSKK_StrList { 33 SDLSKK_ListElement *begin, *end; 34 }; 35 36 typedef struct SDLSKK_HashElement SDLSKK_HashElement; 37 struct SDLSKK_HashElement { 38 SDLSKK_HashElement *next; 39 SDLSKK_Char *key; 40 SDLSKK_StrList *vals; 41 }; 42 43 typedef struct SDLSKK_Map SDLSKK_Map; 44 struct SDLSKK_Map { 45 SDLSKK_HashElement **table; 46 int table_size; 47 }; 48 49 struct SDLSKK_Dictionary { 50 SDLSKK_Map *map; 51 }; 52 53 struct SDLSKK_DictionaryItem { 54 SDLSKK_Dictionary *dict; 55 SDLSKK_Char* hiragana; 56 SDLSKK_StrList* kanji; 57 SDLSKK_ListElement* cur; 58 }; 59 60 61 enum SDLSKK_RomKanaSolveState { 62 SDLSKK_RomKana_NoCandidate, 63 SDLSKK_RomKana_SomeCandidates, 64 SDLSKK_RomKana_OneCandidate, 65 SDLSKK_RomKana_UnresolvedCandidate 66 }; 67 typedef enum SDLSKK_RomKanaSolveState SDLSKK_RomKanaSolveState; 68 69 typedef struct SDLSKK_RomKanaElement SDLSKK_RomKanaElement; 70 struct SDLSKK_RomKanaElement{ 71 SDLSKK_RomKanaElement* next; 72 SDLSKK_Char* key; 73 SDLSKK_Char* next_state; 74 SDLSKK_Char* hiragana; 75 SDLSKK_Char* katakana; 76 }; 77 78 struct SDLSKK_RomKanaRuleTable{ 79 SDLSKK_RomKanaElement *top; 80 }; 81 82 83 typedef void (* SDLSKK_Command)(SDLSKK_Context* context, char key ); 84 85 typedef struct SDLSKK_KeybindElement SDLSKK_KeybindElement; 86 struct SDLSKK_KeybindElement { 87 SDL_keysym key; 88 SDLSKK_Command* commands; 89 SDLSKK_KeybindElement* next; 90 }; 91 92 struct SDLSKK_Keybind { 93 SDLSKK_KeybindElement* top; 94 }; 95 96 struct SDLSKK_Context { 97 SDLSKK_Dictionary *dict; 98 SDLSKK_RomKanaRuleTable* rule_table; 99 100 SDLSKK_XStr* str; 101 int cursor_pos; 102 103 SDLSKK_XStr* prefix; 104 SDLSKK_XStr* henkan_key; 105 int henkan_buf_pos; 106 SDLSKK_Char okuri_char; 107 SDLSKK_XStr* henkan_okurigana; 108 109 SDLSKK_DictionaryItem* dict_item; 110 111 int katakana_on; 112 113 SDLSKK_XStr* display_str; 114 SDLSKK_XStr* minibuffer_str; 115 116 SDLSKK_Mode mode; 117 SDLSKK_Mode old_mode; 118 119 int use_minibuffer; 120 SDLSKK_Context* child_context; 121 SDLSKK_Context* parent_context; 122 123 SDLSKK_XStr* cut_buffer; 124 int marked_point; 125 126 SDLSKK_Keybind* keybind; 127 }; 128 129 130 SDLSKK_Char* SDLSKK_Context_get_display_Str( SDLSKK_Context* context ); 131 SDLSKK_Char* SDLSKK_Context_get_minibuffer_Str( SDLSKK_Context* context ); 132 void SDLSKK_Context_get_henkan_XStr( SDLSKK_Context* context, SDLSKK_XStr* xstr ); 133 134 void SDLSKK_RomKanaRuleTable_add( SDLSKK_RomKanaRuleTable* rule_table, 135 SDLSKK_Char* key, 136 SDLSKK_Char* next_state, 137 SDLSKK_Char* hiragana, 138 SDLSKK_Char* katakana 139 ); 140 141 SDLSKK_RomKanaSolveState SDLSKK_RomKanaRuleTable_get( SDLSKK_RomKanaRuleTable* rule_table, 142 SDLSKK_Char* prefix, 143 SDLSKK_RomKanaElement** candidate ); 144 145 SDLSKK_DictionaryItem* SDLSKK_Dict_get( SDLSKK_Dictionary* dict, 146 SDLSKK_Char *hiragana ); 147 void SDLSKK_Dict_add_empty_yomi( SDLSKK_Dictionary* dict, 148 SDLSKK_Char* yomi ); 149 SDLSKK_Char* SDLSKK_DictItem_get_current( SDLSKK_DictionaryItem* item ); 150 void SDLSKK_DictItem_next( SDLSKK_DictionaryItem* item ); 151 void SDLSKK_DictItem_prev( SDLSKK_DictionaryItem* item ); 152 void SDLSKK_DictItem_reset( SDLSKK_DictionaryItem* item ); 153 void SDLSKK_DictItem_delete( SDLSKK_DictionaryItem* item ); 154 int SDLSKK_DictItem_is_end( SDLSKK_DictionaryItem* item ); 155 int SDLSKK_DictItem_is_begin( SDLSKK_DictionaryItem* item ); 156 void SDLSKK_DictItem_commit( SDLSKK_DictionaryItem* item ); 157 void SDLSKK_DictItem_register_word( SDLSKK_DictionaryItem* item, 158 SDLSKK_Char* new_word ); 159 void SDLSKK_DictItem_set_current( SDLSKK_DictionaryItem* item, 160 SDLSKK_Char* word ); 161 int SDLSKK_DictItem_get_count( SDLSKK_DictionaryItem* item ); 162 163 SDLSKK_Char* SDLSKK_Str_new( SDLSKK_Char * str ); 164 SDLSKK_Char* SDLSKK_Str_new2( char* str ); 165 SDLSKK_Char SDLSKK_get_sc( char* line, int* pos ); 166 SDLSKK_Char* SDLSKK_Str_insert_Char( SDLSKK_Char* str, int pos, SDLSKK_Char c, int max_buf ); 167 SDLSKK_Char* SDLSKK_Str_insert_Str( SDLSKK_Char* str, int pos, SDLSKK_Char *istr, int max_buf ); 168 SDLSKK_Char* SDLSKK_Str_delete_Char( SDLSKK_Char* str, int pos ); 169 void SDLSKK_Str_clear( SDLSKK_Char* str ); 170 SDLSKK_Char* SDLSKK_cstr_tokenize( char* line, char delimiter, int* pos ); 171 void SDLSKK_Str_chop( SDLSKK_Char* str ); 172 char* SDLSKK_Str_to_cstr( SDLSKK_Char* str, char* cstr, size_t size ); 173 int SDLSKK_Str_len( SDLSKK_Char* str ); 174 int SDLSKK_str_equal( SDLSKK_Char *str1, SDLSKK_Char *str2 ); 175 SDLSKK_Char SDLSKK_latin_to_jisx0208_Char( SDLSKK_Char ch ); 176 SDLSKK_Char SDLSKK_hiragana_to_katakana( SDLSKK_Char ch ); 177 SDLSKK_Char SDLSKK_katakana_to_hiragana( SDLSKK_Char ch ); 178 SDLSKK_Char* SDLSKK_Str_hiragana_to_katakana( SDLSKK_Char* str ); 179 SDLSKK_Char* SDLSKK_Str_katakana_to_hiragana( SDLSKK_Char* str ); 180 181 SDLSKK_XStr* SDLSKK_XStr_new1( SDLSKK_Char* str ); 182 SDLSKK_XStr* SDLSKK_XStr_new2( SDLSKK_Char* str, int maxlen ); 183 SDLSKK_XStr* SDLSKK_XStr_new3( char* str ); 184 SDLSKK_XStr* SDLSKK_XStr_new4( char* str, int maxlen ); 185 SDLSKK_XStr* SDLSKK_XStr_new5( SDLSKK_XStr* str ); 186 void SDLSKK_XStr_delete( SDLSKK_XStr* str ); 187 void SDLSKK_XStr_insert_Char( SDLSKK_XStr* str, int pos, SDLSKK_Char c ); 188 void SDLSKK_XStr_insert_Str( SDLSKK_XStr* str, int pos, SDLSKK_Char *istr ); 189 void SDLSKK_XStr_delete_Char( SDLSKK_XStr* str, int pos ); 190 void SDLSKK_XStr_clear( SDLSKK_XStr* str ); 191 void SDLSKK_XStr_concat_Str( SDLSKK_XStr* str1, SDLSKK_Char* str2 ); 192 void SDLSKK_XStr_copy_Str( SDLSKK_XStr* str1, SDLSKK_Char* str2 ); 193 void SDLSKK_XStr_slice_Str( SDLSKK_XStr* dest, SDLSKK_Char* src, int start, int end ); 194 195 SDLSKK_StrList* SDLSKK_StrList_new( void ); 196 SDLSKK_ListElement* SDLSKK_StrList_find( SDLSKK_StrList* list, SDLSKK_Char* val ); 197 void SDLSKK_StrList_insert( SDLSKK_StrList* list, SDLSKK_ListElement *locate, 198 SDLSKK_Char* val, int save ); 199 void SDLSKK_StrList_push( SDLSKK_StrList* list, SDLSKK_Char* val, int save ); 200 void SDLSKK_StrList_shift( SDLSKK_StrList* list, SDLSKK_Char* val, int save ); 201 void SDLSKK_StrList_delete( SDLSKK_StrList* list ); 202 void SDLSKK_StrList_delete_all( SDLSKK_StrList* list ); 203 204 SDLSKK_Map* SDLSKK_Map_new( int table_size ); 205 void SDLSKK_Map_set( SDLSKK_Map* map, SDLSKK_Char* key, SDLSKK_StrList* vals ); 206 SDLSKK_StrList* SDLSKK_Map_get( SDLSKK_Map* map, SDLSKK_Char* key ); 207 void SDLSKK_Map_delete( SDLSKK_Map* map ); 208 void SDLSKK_Map_delete_all( SDLSKK_Map* map ); 209 210 SDLSKK_Command* SDLSKK_convert_command_str( char* command_str ); 211 SDL_keysym SDLSKK_convert_key_str( char* key ); 212 SDLSKK_Command SDLSKK_Keybind_get_command( SDLSKK_Keybind* keybind, 213 SDL_keysym key, SDLSKK_Mode mode ); 214 void SDLSKK_Keybind_set_key( SDLSKK_Keybind* keybing, char* key_str, 215 char* command_str ); 216 void SDLSKK_Keybind_set_default_key( SDLSKK_Keybind* keybind ); 217 218 void* SDLSKK_malloc( size_t size ); 219 void* SDLSKK_realloc( void* ptr, size_t size ); 220 221 void SDLSKK_Char_to_char( SDLSKK_Char c, char *result ); 222 void print_Str( SDLSKK_Char* str ); 223 #endif 224