]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/toolutil/ucmpwrit.c
ICU-6.2.10.tar.gz
[apple/icu.git] / icuSources / tools / toolutil / ucmpwrit.c
1 /**********************************************************************
2 * Copyright (C) 1998-2000, International Business Machines Corporation
3 * and others. All Rights Reserved.
4 **********************************************************************/
5 #include "ucmpwrit.h"
6 #include <stdio.h>
7
8 /*
9 UCMP8 format:
10
11 offset size what
12 ---------------------------------------------
13 0 4 ICU_UCMP8_VERSION
14 4 4 count
15 8 512*2 = 1024 fIndex [uint16's] (UCMP8_kIndexCount*2)
16 1032 1*fCount fArray [int8_t's]
17 + padding (to extend fCount to the nearest multiple of 4)
18 */
19
20 /* Sanity check. */
21 #if (UCMP8_kIndexCount != 512)
22 # error UCMP8_kIndexCount - changed size. Check to see if different pading needed.
23 #endif
24
25 U_CAPI uint32_t U_EXPORT2 udata_write_ucmp8 (UNewDataMemory *pData, const CompactByteArray* array)
26 {
27 int32_t size = 0;
28
29 udata_write32(pData, ICU_UCMP8_VERSION);
30 size += 4;
31
32 udata_write32(pData, array->fCount);
33 size += 4;
34
35 udata_writeBlock(pData, array->fIndex, sizeof(array->fIndex[0])*UCMP8_kIndexCount);
36 size += sizeof(array->fIndex[0])*UCMP8_kIndexCount;
37
38 udata_writeBlock(pData, array->fArray, sizeof(array->fArray[0])*array->fCount);
39 size += sizeof(array->fArray[0])*array->fCount;
40
41 while(size%4) /* end padding */
42 {
43 udata_writePadding(pData, 1); /* Pad total so far to even size */
44 size += 1;
45 }
46
47 return size;
48 }
49
50 /* internal constants*/
51 #if 0
52
53 static const int32_t UCMP16_kMaxUnicode = UCMP16_kMaxUnicode_int;
54 static const int32_t UCMP16_kUnicodeCount = UCMP16_kUnicodeCount_int;
55 static const int32_t UCMP16_kBlockShift = UCMP16_kBlockShift_int;
56 static const int32_t UCMP16_kBlockCount = UCMP16_kBlockCount_int;
57 static const int32_t UCMP16_kBlockBytes = UCMP16_kBlockBytes_int;
58 static const int32_t UCMP16_kIndexShift = UCMP16_kIndexShift_int;
59 static const int32_t UCMP16_kIndexCount = UCMP16_kIndexCount_int;
60 static const uint32_t UCMP16_kBlockMask = UCMP16_kBlockMask_int;
61
62 /*
63 UCMP16 format:
64
65 offset size what
66 ---------------------------------------------
67 0 4 ICU_UCMP16_VERSION
68 4 4 count
69 8 4 blockShift
70 12 4 blockMask
71 16 512*2 = 1024 fIndex [uint16's] (UCMP16_kIndexCount*2)
72 1032 1*fCount fArray [int16's]
73 + padding (to extend fCount to the nearest multiple of 4)
74
75 */
76
77 #if (UCMP16_kIndexCount_int != 512)
78 # error UCMP16_kIndexCount - changed size. Check to see if different pading needed.
79 #endif
80
81 U_CAPI uint32_t U_EXPORT2 udata_write_ucmp16 (UNewDataMemory *pData, const CompactShortArray* array)
82 {
83 int32_t size = 0;
84
85 udata_write32(pData, ICU_UCMP16_VERSION);
86 size += 4;
87
88 udata_write32(pData, array->fCount);
89 size += 4;
90
91 udata_write32(pData, array->kBlockShift);
92 size += 4;
93
94 udata_write32(pData, array->kBlockMask);
95 size += 4;
96
97 udata_writeBlock(pData, array->fIndex, sizeof(array->fIndex[0])*UCMP16_kIndexCount);
98 size += sizeof(array->fIndex[0])*UCMP16_kIndexCount;
99
100 udata_writeBlock(pData, array->fArray, sizeof(array->fArray[0])*array->fCount);
101 size += sizeof(array->fArray[0])*array->fCount;
102
103 while(size%4) /* end padding */
104 {
105 udata_writePadding(pData, 1); /* Pad total so far to even size */
106 size += 1;
107 }
108
109 return size;
110 }
111
112 /*
113 UCMP32 format:
114
115
116 Add format here
117
118
119 offset size what
120 ---------------------------------------------
121 0 4 ICU_UCMP32_VERSION
122 4 4 count
123 16 512*2 = 1024 fIndex [uint16's] (UCMP16_kIndexCount*2)
124 1032 1*fCount fArray [int32's]
125 Padding is not needed for ucmp32, since the array consists of int32's
126 + padding (to extend fCount to the nearest multiple of 4)
127
128 */
129
130 #if (UCMP32_kIndexCount != 512)
131 # error UCMP32_kIndexCount - changed size. Check to see if different pading needed.
132 #endif
133
134 U_CAPI uint32_t U_EXPORT2 udata_write_ucmp32 (UNewDataMemory *pData, const CompactIntArray* array)
135 {
136 int32_t size = 0;
137
138 udata_write32(pData, ICU_UCMP32_VERSION);
139 size += 4;
140
141 udata_write32(pData, array->fCount);
142 size += 4;
143
144 udata_writeBlock(pData, array->fIndex, sizeof(array->fIndex[0])*UCMP32_kIndexCount);
145 size += sizeof(array->fIndex[0])*UCMP32_kIndexCount;
146
147 udata_writeBlock(pData, array->fArray, sizeof(array->fArray[0])*array->fCount);
148 size += sizeof(array->fArray[0])*array->fCount;
149
150 while(size%4) /* end padding */
151 {
152 udata_writePadding(pData, 1); /* Pad total so far to even size */
153 size += 1;
154 }
155
156 return size;
157 }
158
159 #endif
160
161
162
163
164