1 /***************************************************************************
2  *   Copyright (C) 2012~2012 by Yichao Yu                                  *
3  *   yyc1992@gmail.com                                                     *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
19  ***************************************************************************/
20 
21 #ifndef _PINYIN_ENHANCE_MAP_H
22 #define _PINYIN_ENHANCE_MAP_H
23 
24 #define PYENHANCE_MAP_BLANK " \t\b\r\n"
25 
26 #include "stdint.h"
27 
28 typedef struct _PyEnhanceMapWord PyEnhanceMapWord;
29 struct _PyEnhanceMapWord {
30     PyEnhanceMapWord *next;
31 };
32 static inline void*
py_enhance_map_word(const PyEnhanceMapWord * word)33 py_enhance_map_word(const PyEnhanceMapWord *word)
34 {
35     return ((void*)(intptr_t)word) + sizeof(PyEnhanceMapWord);
36 }
37 
38 typedef struct _PyEnhanceMap PyEnhanceMap;
39 struct _PyEnhanceMap {
40     PyEnhanceMapWord *words;
41     UT_hash_handle hh;
42 };
43 
44 static inline PyEnhanceMap*
py_enhance_map_next(PyEnhanceMap * map)45 py_enhance_map_next(PyEnhanceMap *map)
46 {
47     return (PyEnhanceMap*)map->hh.next;
48 }
49 
50 static inline void*
py_enhance_map_key(PyEnhanceMap * map)51 py_enhance_map_key(PyEnhanceMap *map)
52 {
53     return (void*)map + sizeof(PyEnhanceMap);
54 }
55 void PinyinEnhanceMapAdd(PyEnhanceMap **map, FcitxMemoryPool *pool,
56                          const char *key, unsigned int key_l,
57                          const char *word, unsigned int word_l);
58 PyEnhanceMapWord *PinyinEnhanceMapGet(PyEnhanceMap *map,
59                                       const char *key, unsigned int key_l);
60 static inline void
PinyinEnhanceMapClear(PyEnhanceMap ** map,FcitxMemoryPool * pool)61 PinyinEnhanceMapClear(PyEnhanceMap **map, FcitxMemoryPool *pool)
62 {
63     *map = NULL;
64     if (fcitx_likely(pool)) {
65         fcitx_memory_pool_clear(pool);
66     }
67 }
68 void PinyinEnhanceMapLoad(PyEnhanceMap **map, FcitxMemoryPool *pool, FILE *fp);
69 
70 #endif /* _PINYIN_ENHANCE_MAP_H */
71