• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Anthyを正かなづかひの入力と變換に對應させるパッチの作成作業リポジトリ。<git://git.debian.org/git/collab-maint/anthy.git>のmasterブランチからフォーク。


Commit MetaInfo

Revision8b1b6ca38f46316944122c9a8186973556089da9 (tree)
Time2010-08-03 10:10:13
AuthorNIIBE Yutaka <gniibe@fsij...>
CommiterNIIBE Yutaka

Log Message

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

filemap.c.

* src-diclib/filemap.c: Removed.
* src-diclib/file_dic.c (struct file_dic): Directly have PTR

ans SIZE.

(anthy_mmap): Moved here (was: filemap.c).
(anthy_quit_file_dic): Call munmap directly.

* src-splitter/depgraph.c: Delete #include <anthy/filemap.h>.

Change Summary

Incremental Difference

--- a/AUTHORS
+++ b/AUTHORS
@@ -7,7 +7,6 @@ TABATA Yusuke: wrote
77 mkworddic/writewords.c
88 src-diclib/alloc.c
99 src-diclib/conf.c
10- src-diclib/filemap.c
1110 src-diclib/ruleparser.c
1211 src-diclib/xchar.c
1312 src-diclib/xstr.c
--- a/ChangeLog
+++ b/ChangeLog
@@ -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+
156 2010-08-02 NIIBE Yutaka <gniibe@fsij.org>
257
358 * src-worddic/record.c (read_session): Don't change
--- a/anthy/Makefile.am
+++ b/anthy/Makefile.am
@@ -3,7 +3,6 @@ noinst_HEADERS = xstr.h xchar.h dic.h wtype.h\
33 conf.h record.h alloc.h\
44 ruleparser.h splitter.h \
55 segment.h ordering.h \
6- filemap.h \
76 logger.h segclass.h \
87 depgraph.h \
98 textdic.h matrix.h \
--- a/anthy/filemap.h
+++ /dev/null
@@ -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
--- a/src-diclib/Makefile.am
+++ b/src-diclib/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/ -DCONF_DIR=\"$(sysconfdir)\"
22
33 libdiclib_la_SOURCES = \
44 diclib.c \
5- file_dic.c filemap.c \
5+ file_dic.c \
66 xstr.c xchar.c \
77 alloc.c conf.c \
88 logger.c \
--- a/src-diclib/file_dic.c
+++ b/src-diclib/file_dic.c
@@ -1,8 +1,12 @@
11 #include <stdio.h>
22 #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>
38
49 #include <anthy/diclib.h>
5-#include <anthy/filemap.h>
610 #include <anthy/alloc.h>
711 #include <anthy/conf.h>
812 #include <anthy/logger.h>
@@ -13,7 +17,8 @@
1317 */
1418 struct file_dic
1519 {
16- struct filemapping *mapping;
20+ void *ptr;
21+ size_t size;
1722 };
1823
1924 static struct file_dic fdic;
@@ -22,7 +27,7 @@ void*
2227 anthy_file_dic_get_section(const char* section_name)
2328 {
2429 int i;
25- char* head = anthy_mmap_address(fdic.mapping);
30+ char* head = (char *)fdic.ptr;
2631 int* p = (int*)head;
2732 int entry_num = anthy_dic_ntohl(*p++);
2833
@@ -37,6 +42,42 @@ anthy_file_dic_get_section(const char* section_name)
3742 return NULL;
3843 }
3944
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+
4081 int
4182 anthy_init_file_dic(void)
4283 {
@@ -48,8 +89,7 @@ anthy_init_file_dic(void)
4889 }
4990
5091 /* 辞書をメモリ上にmapする */
51- fdic.mapping = anthy_mmap(fn, 0);
52- if (!fdic.mapping) {
92+ if (anthy_mmap (fn) < 0) {
5393 anthy_log(0, "failed to init file dic.\n");
5494 return -1;
5595 }
@@ -60,6 +100,6 @@ anthy_init_file_dic(void)
60100 void
61101 anthy_quit_file_dic(void)
62102 {
63- anthy_munmap(fdic.mapping);
103+ munmap (fdic.ptr, fdic.size);
64104 }
65105
--- a/src-diclib/filemap.c
+++ /dev/null
@@ -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-}
--- a/src-splitter/depgraph.c
+++ b/src-splitter/depgraph.c
@@ -29,7 +29,6 @@
2929 #include <anthy/conf.h>
3030 #include <anthy/ruleparser.h>
3131 #include <anthy/xstr.h>
32-#include <anthy/filemap.h>
3332 #include <anthy/logger.h>
3433 #include <anthy/segclass.h>
3534 #include <anthy/splitter.h>