2
*******************************************************************************
4
* Copyright (C) 1998-2000, International Business Machines
5
* Corporation and others. All Rights Reserved.
7
*******************************************************************************
11
* Modification History:
13
* Date Name Description
14
* 06/01/99 stephen Creation.
15
*******************************************************************************
23
#include "unicode/ustring.h"
29
static void write_ustring(FileStream *rb, const UChar *data);
30
static void write_string(FileStream *rb, const char *data);
31
static void write_strlist(FileStream *rb, const char *name,
32
const struct SStringList *list);
33
static void write_strlist2d(FileStream *rb, const char *name,
34
const struct SStringList2d *list);
35
static void write_taglist(FileStream *rb, const char *name,
36
const struct STaggedList *list);
39
static const int32_t sBOM = 0x021C;
41
static const int32_t sEOF = -1;
43
static const int32_t sSTRINGLIST = 1;
44
static const int32_t sSTRINGLIST2D = 2;
45
static const int32_t sTAGGEDLIST = 3;
47
static const UChar gCollationElementsTag [] = {
48
/* "CollationElements" */
49
0x0043, 0x006f, 0x006c, 0x006c, 0x0061, 0x0074, 0x0069, 0x006f, 0x006e,
50
0x0045, 0x006c, 0x0065, 0x006d, 0x0065, 0x006e, 0x0074, 0x0073, 0x0000
53
/* Write a null-terminated UChar array */
55
write_ustring(FileStream *rb,
62
/* Write the string's length */
63
T_FileStream_write(rb, &len, sizeof(len));
65
/* Write the string's data */
66
T_FileStream_write(rb, data, sizeof(UChar) * len);
70
write_string(FileStream *rb,
74
len = uprv_strlen(data);
75
T_FileStream_write(rb, &len, sizeof(len));
77
T_FileStream_write(rb, data, sizeof(char) * len);
80
/* Write a string list */
82
write_strlist(FileStream *rb,
84
const struct SStringList *list)
88
/* Write out the value indicating this is a string list */
89
T_FileStream_write(rb, &sSTRINGLIST, sizeof(sSTRINGLIST));
91
/* Write the name of this string list */
92
write_string(rb, name);
94
/* Write the item count */
95
T_FileStream_write(rb, &list->fCount, sizeof(list->fCount));
97
/* Write each string in the list */
98
for(i = 0; i < list->fCount; ++i) {
99
write_ustring(rb, list->fData[i]);
103
/* Write a 2-d string list */
105
write_strlist2d(FileStream *rb,
107
const struct SStringList2d *list)
112
/* Write out the value indicating this is a 2-d string list */
113
T_FileStream_write(rb, &sSTRINGLIST2D, sizeof(sSTRINGLIST2D));
115
/* Write the name of this 2-d string list */
116
write_string(rb, name);
118
/* Write the row count */
119
T_FileStream_write(rb, &list->fRowCount, sizeof(list->fRowCount));
121
/* Write out each row */
122
for(i = 0; i < list->fRowCount; ++i) {
123
itemcount = (i == list->fRowCount - 1 ? list->fCount: list->fRows[i+1])
126
/* Write out the count of strings in this row */
127
T_FileStream_write(rb, &itemcount, sizeof(itemcount));
129
/* Write out each string in the row */
130
for(j = 0; j < itemcount; ++j) {
131
write_ustring(rb, list->fData[list->fRows[i] + j]);
136
/* Write a tagged list */
138
write_taglist(FileStream *rb,
140
const struct STaggedList *list)
143
struct SStringPair *current;
145
/* Write out the value indicating this is a tagged list */
146
T_FileStream_write(rb, &sTAGGEDLIST, sizeof(sTAGGEDLIST));
148
/* Write the name of this tagged list */
149
write_string(rb, name);
151
/* Write the item count */
152
T_FileStream_write(rb, &list->fCount, sizeof(list->fCount));
154
/* Write out each key/value pair */
155
current = list->fFirst;
156
while(current != NULL) {
157
write_string(rb, current->fKey);
158
write_ustring(rb, current->fValue);
159
current = current->fNext;
163
/* for(i = 0; i < list->fCount; ++i) {
164
// write_ustring(rb, list->fData[i].fKey);
165
// write_ustring(rb, list->fData[i].fValue);
169
/* Write a parsed SRBItemList to a file */
171
rb_write(FileStream *f,
172
struct SRBItemList *data,
176
struct SRBItem *item;
178
if(U_FAILURE(*status)) return;
180
/* Write the byte order mark to the file */
181
T_FileStream_write(f, &sBOM, sizeof(sBOM));
183
/* Write the locale name to the file */
184
write_ustring(f, data->fLocale);
188
/* Successively write each list item */
189
/* for(i = 0; i < data->fCount; ++i) { */
190
while(item != NULL) {
192
/* item = data->fData[i]; */
194
switch(item->fData->fType) {
196
/*if(u_strcmp(item->fTag, gCollationElementsTag) == 0)
197
puts("got CollationElements");*/
198
write_strlist(f, item->fTag, &item->fData->u.fStringList);
202
write_strlist2d(f, item->fTag, &item->fData->u.fStringList2d);
206
write_taglist(f, item->fTag, &item->fData->u.fTaggedList);
210
*status = U_INTERNAL_PROGRAM_ERROR;
211
setErrorText("Unexpected empty item found");
218
/* Indicate the end of the data */
219
T_FileStream_write(f, &sEOF, sizeof(sEOF));
221
/* Check if any errors occurred during writing */
222
if(T_FileStream_error(f) != 0) {
223
*status = U_FILE_ACCESS_ERROR;