Anthyを正かなづかひの入力と變換に對應させるパッチの作成作業リポジトリ。<git://git.debian.org/git/collab-maint/anthy.git>のmasterブランチからフォーク。
Revision | 8b1b6ca38f46316944122c9a8186973556089da9 (tree) |
---|---|
Time | 2010-08-03 10:10:13 |
Author | NIIBE Yutaka <gniibe@fsij...> |
Commiter | NIIBE Yutaka |
kill filemap.c, just mmap inside file_dic.c.
2010-08-03 NIIBE Yutaka <gniibe@fsij.org>
* anthy/Makefile.am (noinst_HEADERS): Removed filemap.h.
* anthy/filemap.h: Removed.
* src-diclib/Makefile.am (libdiclib_la_SOURCES): Removed
* src-diclib/filemap.c: Removed.
* src-diclib/file_dic.c (struct file_dic): Directly have PTR
(anthy_mmap): Moved here (was: filemap.c).
(anthy_quit_file_dic): Call munmap directly.
* src-splitter/depgraph.c: Delete #include <anthy/filemap.h>.
@@ -7,7 +7,6 @@ TABATA Yusuke: wrote | ||
7 | 7 | mkworddic/writewords.c |
8 | 8 | src-diclib/alloc.c |
9 | 9 | src-diclib/conf.c |
10 | - src-diclib/filemap.c | |
11 | 10 | src-diclib/ruleparser.c |
12 | 11 | src-diclib/xchar.c |
13 | 12 | src-diclib/xstr.c |
@@ -1,3 +1,58 @@ | ||
1 | +2010-08-03 NIIBE Yutaka <gniibe@fsij.org> | |
2 | + | |
3 | + * anthy/Makefile.am (noinst_HEADERS): Removed filemap.h. | |
4 | + * anthy/filemap.h: Removed. | |
5 | + | |
6 | + * src-diclib/Makefile.am (libdiclib_la_SOURCES): Removed | |
7 | + filemap.c. | |
8 | + * src-diclib/filemap.c: Removed. | |
9 | + * src-diclib/file_dic.c (struct file_dic): Directly have PTR | |
10 | + ans SIZE. | |
11 | + (anthy_mmap): Moved here (was: filemap.c). | |
12 | + (anthy_quit_file_dic): Call munmap directly. | |
13 | + | |
14 | + * src-splitter/depgraph.c: Delete #include <anthy/filemap.h>. | |
15 | + | |
16 | +2010-08-02 NIIBE Yutaka <gniibe@fsij.org> | |
17 | + | |
18 | + * anthy/texttrie.h: Removed. | |
19 | + * anthy/Makefile.am (noinst_HEADERS): Remove texttrie.h. | |
20 | + | |
21 | + * src-worddic/Makefile.am (libanthydic_la_SOURCES): Remove | |
22 | + texttrie.c. | |
23 | + | |
24 | + * src-worddic/dic_util.c (anthy_private_tt_dic, find_next_key) | |
25 | + (delete_prefix, encoding_prefix, find_same_word): Removed. | |
26 | + (struct iterate_contex): Removed in_tt and key_buf. | |
27 | + | |
28 | + (anthy_dic_util_init, select_first_entry_in_textdic): Don't | |
29 | + access to in_tt field. | |
30 | + (anthy_priv_dic_delete): Don't call delete_prefix. | |
31 | + (anthy_priv_dic_select_first_entry): Just call | |
32 | + select_first_entry_in_textdic. | |
33 | + (anthy_priv_dic_select_next_entry): Don't call find_next_key. | |
34 | + (anthy_priv_dic_get_index): Don't access in_tt and key_buf. | |
35 | + (anthy_priv_dic_get_freq): Just call anthy_parse_word_line. | |
36 | + (anthy_priv_dic_get_wtype, anthy_priv_dic_get_word): Don't | |
37 | + call anthy_trie_find. | |
38 | + (add_word_to_textdic): Don't call anthy_trie_delete. | |
39 | + | |
40 | + * src-worddic/priv_dic.c (anthy_private_tt_dic, open_tt_dic) | |
41 | + (copy_words_from_tt): Removed. | |
42 | + (anthy_priv_dic_update): Don't call anthy_trie_update_mapping. | |
43 | + (anthy_copy_words_from_private_dic): Don't call copy_words_from_tt. | |
44 | + (anthy_init_private_dic): Dont' call open_tt_dic and anthy_trie_close. | |
45 | + (anthy_release_private_dic): Don't call anthy_trie_close. | |
46 | + | |
47 | + * src-worddic/texttrie.c: Removed. | |
48 | + | |
49 | + * src-worddic/word_dic.c: Comment fix. | |
50 | + | |
51 | + * src-worddic/dic_main.h (anthy_priv_dic_update): Removed. | |
52 | + * src-worddic/priv_dic.c: Likewise. | |
53 | + * src-worddic/word_dic.c (anthy_lock_dic): Don't call | |
54 | + anthy_priv_dic_update. | |
55 | + | |
1 | 56 | 2010-08-02 NIIBE Yutaka <gniibe@fsij.org> |
2 | 57 | |
3 | 58 | * src-worddic/record.c (read_session): Don't change |
@@ -3,7 +3,6 @@ noinst_HEADERS = xstr.h xchar.h dic.h wtype.h\ | ||
3 | 3 | conf.h record.h alloc.h\ |
4 | 4 | ruleparser.h splitter.h \ |
5 | 5 | segment.h ordering.h \ |
6 | - filemap.h \ | |
7 | 6 | logger.h segclass.h \ |
8 | 7 | depgraph.h \ |
9 | 8 | textdic.h matrix.h \ |
@@ -1,14 +0,0 @@ | ||
1 | -/* mmapを抽象化する */ | |
2 | -#ifndef _filemap_h_included_ | |
3 | -#define _filemap_h_included_ | |
4 | - | |
5 | -/* メモリ上にmapされたファイルのハンドル */ | |
6 | -struct filemapping; | |
7 | - | |
8 | -struct filemapping *anthy_mmap(const char *fn, int wr); | |
9 | -void *anthy_mmap_address(struct filemapping *m); | |
10 | -int anthy_mmap_size(struct filemapping *m); | |
11 | -int anthy_mmap_is_writable(struct filemapping *m); | |
12 | -void anthy_munmap(struct filemapping *m); | |
13 | - | |
14 | -#endif |
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/ -DCONF_DIR=\"$(sysconfdir)\" | ||
2 | 2 | |
3 | 3 | libdiclib_la_SOURCES = \ |
4 | 4 | diclib.c \ |
5 | - file_dic.c filemap.c \ | |
5 | + file_dic.c \ | |
6 | 6 | xstr.c xchar.c \ |
7 | 7 | alloc.c conf.c \ |
8 | 8 | logger.c \ |
@@ -1,8 +1,12 @@ | ||
1 | 1 | #include <stdio.h> |
2 | 2 | #include <string.h> |
3 | +#include <sys/types.h> | |
4 | +#include <sys/stat.h> | |
5 | +#include <fcntl.h> | |
6 | +#include <unistd.h> | |
7 | +#include <sys/mman.h> | |
3 | 8 | |
4 | 9 | #include <anthy/diclib.h> |
5 | -#include <anthy/filemap.h> | |
6 | 10 | #include <anthy/alloc.h> |
7 | 11 | #include <anthy/conf.h> |
8 | 12 | #include <anthy/logger.h> |
@@ -13,7 +17,8 @@ | ||
13 | 17 | */ |
14 | 18 | struct file_dic |
15 | 19 | { |
16 | - struct filemapping *mapping; | |
20 | + void *ptr; | |
21 | + size_t size; | |
17 | 22 | }; |
18 | 23 | |
19 | 24 | static struct file_dic fdic; |
@@ -22,7 +27,7 @@ void* | ||
22 | 27 | anthy_file_dic_get_section(const char* section_name) |
23 | 28 | { |
24 | 29 | int i; |
25 | - char* head = anthy_mmap_address(fdic.mapping); | |
30 | + char* head = (char *)fdic.ptr; | |
26 | 31 | int* p = (int*)head; |
27 | 32 | int entry_num = anthy_dic_ntohl(*p++); |
28 | 33 |
@@ -37,6 +42,42 @@ anthy_file_dic_get_section(const char* section_name) | ||
37 | 42 | return NULL; |
38 | 43 | } |
39 | 44 | |
45 | +static int | |
46 | +anthy_mmap (const char *fn) | |
47 | +{ | |
48 | + int fd; | |
49 | + void *ptr; | |
50 | + struct stat st; | |
51 | + | |
52 | + fd = open (fn, O_RDONLY); | |
53 | + if (fd == -1) { | |
54 | + anthy_log(0, "Failed to open (%s).\n", fn); | |
55 | + return -1; | |
56 | + } | |
57 | + | |
58 | + if (fstat(fd, &st) < 0) { | |
59 | + anthy_log(0, "Failed to stat() (%s).\n", fn); | |
60 | + close(fd); | |
61 | + return -1; | |
62 | + } | |
63 | + if (st.st_size == 0) { | |
64 | + anthy_log(0, "Failed to mmap 0size file (%s).\n", fn); | |
65 | + close(fd); | |
66 | + return -1; | |
67 | + } | |
68 | + | |
69 | + ptr = mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | |
70 | + close(fd); | |
71 | + if (ptr == MAP_FAILED) { | |
72 | + anthy_log(0, "Failed to mmap() (%s).\n", fn); | |
73 | + return -1; | |
74 | + } | |
75 | + | |
76 | + fdic.ptr = ptr; | |
77 | + fdic.size = st.st_size; | |
78 | + return 0; | |
79 | +} | |
80 | + | |
40 | 81 | int |
41 | 82 | anthy_init_file_dic(void) |
42 | 83 | { |
@@ -48,8 +89,7 @@ anthy_init_file_dic(void) | ||
48 | 89 | } |
49 | 90 | |
50 | 91 | /* 辞書をメモリ上にmapする */ |
51 | - fdic.mapping = anthy_mmap(fn, 0); | |
52 | - if (!fdic.mapping) { | |
92 | + if (anthy_mmap (fn) < 0) { | |
53 | 93 | anthy_log(0, "failed to init file dic.\n"); |
54 | 94 | return -1; |
55 | 95 | } |
@@ -60,6 +100,6 @@ anthy_init_file_dic(void) | ||
60 | 100 | void |
61 | 101 | anthy_quit_file_dic(void) |
62 | 102 | { |
63 | - anthy_munmap(fdic.mapping); | |
103 | + munmap (fdic.ptr, fdic.size); | |
64 | 104 | } |
65 | 105 |
@@ -1,135 +0,0 @@ | ||
1 | -/* mmapを抽象化する | |
2 | - * | |
3 | - * *Unix系のシステムコールをソース中に散らさないため | |
4 | - * *将来的には一つのファイルを複数の目的にmapすることも考慮 | |
5 | - * | |
6 | - * Copyright (C) 2005 TABATA Yusuke | |
7 | - * | |
8 | - */ | |
9 | -/* | |
10 | - This library is free software; you can redistribute it and/or | |
11 | - modify it under the terms of the GNU Lesser General Public | |
12 | - License as published by the Free Software Foundation; either | |
13 | - version 2 of the License, or (at your option) any later version. | |
14 | - | |
15 | - This library is distributed in the hope that it will be useful, | |
16 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | - Lesser General Public License for more details. | |
19 | - | |
20 | - You should have received a copy of the GNU Lesser General Public | |
21 | - License along with this library; if not, write to the Free Software | |
22 | - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 | - */ | |
24 | -#include <sys/types.h> | |
25 | -#include <sys/mman.h> | |
26 | -#include <sys/stat.h> | |
27 | -#include <unistd.h> | |
28 | -#include <fcntl.h> | |
29 | -#include <stdlib.h> | |
30 | - | |
31 | -#include <anthy/filemap.h> | |
32 | -#include <anthy/logger.h> | |
33 | - | |
34 | -struct filemapping { | |
35 | - /* 書き込みモード */ | |
36 | - int wr; | |
37 | - /* mmapしたアドレス */ | |
38 | - void *ptr; | |
39 | - /* mmapした領域の長さ */ | |
40 | - size_t size; | |
41 | -}; | |
42 | - | |
43 | -struct filemapping * | |
44 | -anthy_mmap(const char *fn, int wr) | |
45 | -{ | |
46 | - int fd; | |
47 | - void *ptr; | |
48 | - int r; | |
49 | - struct filemapping *m; | |
50 | - struct stat st; | |
51 | - int prot; | |
52 | - int flags; | |
53 | - mode_t mode; | |
54 | - | |
55 | - if (wr) { | |
56 | - prot = PROT_READ | PROT_WRITE; | |
57 | - flags = O_RDWR; | |
58 | - mode = S_IRUSR | S_IWUSR; | |
59 | - } else { | |
60 | - prot = PROT_READ; | |
61 | - flags = O_RDONLY; | |
62 | - mode = S_IRUSR; | |
63 | - } | |
64 | - | |
65 | - fd = open(fn, flags, mode); | |
66 | - | |
67 | - if (fd == -1) { | |
68 | - anthy_log(0, "Failed to open (%s).\n", fn); | |
69 | - return NULL; | |
70 | - } | |
71 | - | |
72 | - r = fstat(fd, &st); | |
73 | - if (r == -1) { | |
74 | - anthy_log(0, "Failed to stat() (%s).\n", fn); | |
75 | - close(fd); | |
76 | - return NULL; | |
77 | - } | |
78 | - if (st.st_size == 0) { | |
79 | - anthy_log(0, "Failed to mmap 0size file (%s).\n", fn); | |
80 | - close(fd); | |
81 | - return NULL; | |
82 | - } | |
83 | - | |
84 | - ptr = mmap(NULL, st.st_size, prot, MAP_SHARED, fd, 0); | |
85 | - close(fd); | |
86 | - if (ptr == MAP_FAILED) { | |
87 | - anthy_log(0, "Failed to mmap() (%s).\n", fn); | |
88 | - return NULL; | |
89 | - } | |
90 | - | |
91 | - /* mmapに成功したので情報を返す */ | |
92 | - m = malloc(sizeof(struct filemapping)); | |
93 | - m->size = st.st_size; | |
94 | - m->ptr = ptr; | |
95 | - m->wr = wr; | |
96 | - | |
97 | - return m; | |
98 | -} | |
99 | - | |
100 | -void * | |
101 | -anthy_mmap_address(struct filemapping *m) | |
102 | -{ | |
103 | - if (!m) { | |
104 | - return NULL; | |
105 | - } | |
106 | - return m->ptr; | |
107 | -} | |
108 | - | |
109 | -int | |
110 | -anthy_mmap_size(struct filemapping *m) | |
111 | -{ | |
112 | - if (!m) { | |
113 | - return 0; | |
114 | - } | |
115 | - return m->size; | |
116 | -} | |
117 | - | |
118 | -int | |
119 | -anthy_mmap_is_writable(struct filemapping *m) | |
120 | -{ | |
121 | - if (!m) { | |
122 | - return 0; | |
123 | - } | |
124 | - return m->wr; | |
125 | -} | |
126 | - | |
127 | -void | |
128 | -anthy_munmap(struct filemapping *m) | |
129 | -{ | |
130 | - if (!m) { | |
131 | - return ; | |
132 | - } | |
133 | - munmap(m->ptr, m->size); | |
134 | - free(m); | |
135 | -} |
@@ -29,7 +29,6 @@ | ||
29 | 29 | #include <anthy/conf.h> |
30 | 30 | #include <anthy/ruleparser.h> |
31 | 31 | #include <anthy/xstr.h> |
32 | -#include <anthy/filemap.h> | |
33 | 32 | #include <anthy/logger.h> |
34 | 33 | #include <anthy/segclass.h> |
35 | 34 | #include <anthy/splitter.h> |