memmap_common.c

filter: Statementstmt 84.6% 22 / 26 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 75.0% 30 / 40 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« getcode.c ↑ Summary Japanese.xs »
1 /* ----------------------------------------------------------------------------
2 * memmap_common.c
3 * memmap, common routines.
4 * ----------------------------------------------------------------------------
5 * Mastering programed by YAMASHINA Hio
6 * ----------------------------------------------------------------------------
7 * $Id: memmap_common.c 4697 2007-09-14 06:17:00Z pho $
8 * ------------------------------------------------------------------------- */
9  
10 #include "Japanese.h"
11  
12 /* SJIS <=> UTF8 mapping table */
13 /* (ja:) SJIS <=> UTF8 ÊÑ´¹¥Æ¡¼¥Ö¥ë */
14 /* index is in 0..0xffff */
15 UJ_UINT8 const* g_u2s_table;
16 UJ_UINT8 const* g_s2u_table;
17  
18 /* i-mode/j-sky/dot-i³¨Ê¸»ú <=> UTF8 ÊÑ´¹¥Æ¡¼¥Ö¥ë */
19 UJ_UINT32 const* g_ei2u1_table;
20 UJ_UINT32 const* g_ei2u2_table;
21 UJ_UINT16 const* g_eu2i1_table;
22 UJ_UINT16 const* g_eu2i2_table;
23 UJ_UINT32 const* g_ej2u1_table;
24 UJ_UINT32 const* g_ej2u2_table;
25 UJ_UINT8 const* g_eu2j1_table; /* char [][5] */
26 UJ_UINT8 const* g_eu2j2_table; /* char [][5] */
27 UJ_UINT32 const* g_ed2u_table;
28 UJ_UINT16 const* g_eu2d_table;
29  
30 /* i-mode/j-sky/dot-i³¨Ê¸»ú <=> UTF8 ÊÑ´¹¥Æ¡¼¥Ö¥ë¤ÎÍ×ÁÇ¿ô */
31 /* ¥Ð¥¤¥È¿ô¤Ç¤Ê¤¯Í×ÁÇ¿ô */
32 int g_ei2u1_size;
33 int g_ei2u2_size;
34 int g_eu2i1_size;
35 int g_eu2i2_size;
36 int g_ej2u1_size;
37 int g_ej2u2_size;
38 int g_eu2j1_size;
39 int g_eu2j2_size;
40 int g_ed2u_size;
41 int g_eu2d_size;
42  
43 /* au <=> ut8 */
44 UJ_UINT32 const* g_ea2u1_table;
45 int g_ea2u1_size;
46 UJ_UINT32 const* g_ea2u2_table;
47 int g_ea2u2_size;
48 UJ_UINT16 const* g_eu2a1_table;
49 int g_eu2a1_size;
50 UJ_UINT16 const* g_eu2a2_table;
51 int g_eu2a2_size;
52 /* au(s) <=> ut8 */
53 UJ_UINT32 const* g_ea2u1s_table;
54 int g_ea2u1s_size;
55 UJ_UINT32 const* g_ea2u2s_table;
56 int g_ea2u2s_size;
57 UJ_UINT16 const* g_eu2a1s_table;
58 int g_eu2a1s_size;
59 UJ_UINT16 const* g_eu2a2s_table;
60 int g_eu2a2s_size;
61  
62  
63 /* ----------------------------------------------------------------------------
64 * split mapping table.
65 */
66 void
67 27 do_memmap_set(const char* mmap_pmfile, int mmap_pmfile_size)
68 {
69 HV* hv_table;
70 int headlen, proglen;
71
72 assert( mmap_pmfile!=NULL );
73 assert( mmap_pmfile_size!=0 );
74
75 {
76 SV* sv;
77 27 sv = get_sv("Unicode::Japanese::PurePerl::HEADLEN",0);
78 assert( sv!=NULL && "HEADLEN is not NULL");
79 27 headlen = SvIV(sv);
80 assert( headlen>0 );
81 27 sv = get_sv("Unicode::Japanese::PurePerl::PROGLEN",0);
82 assert( sv!=NULL && "PROGLEN is not NULL");
83 27 proglen = SvIV(sv);
84 assert( proglen>0 );
85 }
86
87 {
88 /* get offset table for embeded data */
89 27 SV* sv_hvref_table = get_sv("Unicode::Japanese::PurePerl::TABLE",0);
90 assert(sv_hvref_table!=NULL);
91 assert(SvROK(sv_hvref_table));
92 27 hv_table = (HV*)SvRV(sv_hvref_table);
93 assert(hv_table!=NULL);
94 assert(SvTYPE((SV*)hv_table)==SVt_PVHV);
95 }
96
97 {
98 int dummy;
99 struct
100 {
101 const char* filename;
102 const UJ_UINT8** data_ptr;
103 int* size_ptr;
104 27 } *ptr, embeded[] =
105 {
106 /* sjis<=>utf-8 */
107 { "jcode/s2u.dat", &g_s2u_table, &dummy, },
108 { "jcode/u2s.dat", &g_u2s_table, &dummy, },
109 /* i-mode */
110 { "jcode/emoji2/eu2i.dat", (const UJ_UINT8**)&g_eu2i1_table, &g_eu2i1_size, },
111 { "jcode/emoji2/ei2u.dat", (const UJ_UINT8**)&g_ei2u1_table, &g_ei2u1_size, },
112 { "jcode/emoji2/eu2i2.dat",(const UJ_UINT8**)&g_eu2i2_table, &g_eu2i2_size, },
113 { "jcode/emoji2/ei2u2.dat",(const UJ_UINT8**)&g_ei2u2_table, &g_ei2u2_size, },
114 /* vodafone */
115 { "jcode/emoji2/eu2j.dat", (const UJ_UINT8**)&g_eu2j1_table, &g_eu2j1_size, },
116 { "jcode/emoji2/ej2u.dat", (const UJ_UINT8**)&g_ej2u1_table, &g_ej2u1_size, },
117 { "jcode/emoji2/eu2j2.dat",(const UJ_UINT8**)&g_eu2j2_table, &g_eu2j2_size, },
118 { "jcode/emoji2/ej2u2.dat",(const UJ_UINT8**)&g_ej2u2_table, &g_ej2u2_size, },
119 /* dot-i */
120 { "jcode/emoji2/eu2d.dat", (const UJ_UINT8**)&g_eu2d_table, &g_eu2d_size, },
121 { "jcode/emoji2/ed2u.dat", (const UJ_UINT8**)&g_ed2u_table, &g_ed2u_size, },
122 /* au */
123 { "jcode/emoji2/eu2a.dat", (const UJ_UINT8**)&g_eu2a1_table, &g_eu2a1_size, },
124 { "jcode/emoji2/ea2u.dat", (const UJ_UINT8**)&g_ea2u1_table, &g_ea2u1_size, },
125 { "jcode/emoji2/eu2a2.dat",(const UJ_UINT8**)&g_eu2a2_table, &g_eu2a2_size, },
126 { "jcode/emoji2/ea2u2.dat",(const UJ_UINT8**)&g_ea2u2_table, &g_ea2u2_size, },
127 /* au(s) */
128 { "jcode/emoji2/eu2as.dat", (const UJ_UINT8**)&g_eu2a1s_table, &g_eu2a1s_size, },
129 { "jcode/emoji2/ea2us.dat", (const UJ_UINT8**)&g_ea2u1s_table, &g_ea2u1s_size, },
130 { "jcode/emoji2/eu2a2s.dat",(const UJ_UINT8**)&g_eu2a2s_table, &g_eu2a2s_size, },
131 { "jcode/emoji2/ea2u2s.dat",(const UJ_UINT8**)&g_ea2u2s_table, &g_ea2u2s_size, },
132 /* terminator. */
133 {
134 NULL, NULL, NULL,
135 },
136 };
137 567 ▶ for( ptr=embeded; ptr->filename!=NULL; ++ptr )
Branch: 1 branch
BranchTrueFalseTotal
for( ptr=embeded; ptr->filename!=NULL; ++ptr ) 540 27 567
138 {
139 SV** sv_entryref;
140 HV* hv_entry;
141 SV** sv_offset;
142 SV** sv_length;
143 IV offset;
144 IV length;
145
146 /* sv_entryref = $TABLE->{$filename} */
147 540 sv_entryref = hv_fetch(hv_table,ptr->filename, strlen(ptr->filename), 0);
148 540 ▶ if( sv_entryref==NULL )
Branch: 1 branch
BranchTrueFalseTotal
if( sv_entryref==NULL ) 0 540 540
149 {
150 0 croak("Unicode::Japanese#do_memmap, embedded file [%s] not found",ptr->filename);
151 }
152 /* assert(isa(sv_entryref,"HASH")) */
153 540 ▶ hv_entry = SvROK(*sv_entryref) ? (HV*)SvRV(*sv_entryref) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
hv_entry = SvROK(*sv_entryref) ? (HV*)SvRV(*sv_entryref) : NULL; 540 0 540
154 540 ▶ if( hv_entry!=NULL && SvTYPE((SV*)hv_entry)!=SVt_PVHV )
Branch: 2 branches
BranchTrueFalseTotal
if( hv_entry!=NULL && SvTYPE((SV*)hv_entry)!=SVt_PVHV ) 540 0 540
if( hv_entry!=NULL && SvTYPE((SV*)hv_entry)!=SVt_PVHV ) 0 540 540
155 {
156 0 croak("Unicode::Japanese#do_memmap, embedded file entry [%s] is not hashref",ptr->filename);
157 }
158 /* sv_offset = $hv_entry{"offset"} */
159 /* sv_length = $hv_entry{"length"} */
160 540 sv_offset = hv_fetch(hv_entry,"offset",6,0);
161 540 sv_length = hv_fetch(hv_entry,"length",6,0);
162 540 ▶ if( sv_offset==NULL )
Branch: 1 branch
BranchTrueFalseTotal
if( sv_offset==NULL ) 0 540 540
163 {
164 0 croak("Unicode::Japanese#do_memmap, no offset for embedded file entry [%s]",ptr->filename);
165 }
166 540 ▶ if( sv_length==NULL )
Branch: 1 branch
BranchTrueFalseTotal
if( sv_length==NULL ) 0 540 540
167 {
168 0 croak("Unicode::Japanese#do_memmap, no length for embedded file entry [%s]",ptr->filename);
169 }
170 540 offset = SvIV(*sv_offset);
171 540 length = SvIV(*sv_length);
172 540 *ptr->data_ptr = (const UJ_UINT8*)mmap_pmfile + proglen + headlen + offset;
173 540 *ptr->size_ptr = length;
174 /* printf("[%s] offset: %d, length: %d\n", ptr->filename, offset, length); */
175 }
176 }
177 27 return;
178 }
179  
180 /* ----------------------------------------------------------------------------
181 * End of File.
182 * ------------------------------------------------------------------------- */
« getcode.c ↑ Summary Japanese.xs »