|
1 /* |
|
2 ******************************************************************************* |
|
3 * |
|
4 * Copyright (C) 2000-2011, International Business Machines |
|
5 * Corporation and others. All Rights Reserved. |
|
6 * |
|
7 ******************************************************************************* |
|
8 * |
|
9 * File reslist.h |
|
10 * |
|
11 * Modification History: |
|
12 * |
|
13 * Date Name Description |
|
14 * 02/21/00 weiv Creation. |
|
15 ******************************************************************************* |
|
16 */ |
|
17 |
|
18 #ifndef RESLIST_H |
|
19 #define RESLIST_H |
|
20 |
|
21 #define KEY_SPACE_SIZE 65536 |
|
22 #define RESLIST_MAX_INT_VECTOR 2048 |
|
23 |
|
24 #include "unicode/utypes.h" |
|
25 #include "unicode/ures.h" |
|
26 #include "unicode/ustring.h" |
|
27 #include "uresdata.h" |
|
28 #include "cmemory.h" |
|
29 #include "cstring.h" |
|
30 #include "unewdata.h" |
|
31 #include "ustr.h" |
|
32 #include "uhash.h" |
|
33 |
|
34 U_CDECL_BEGIN |
|
35 |
|
36 typedef struct KeyMapEntry { |
|
37 int32_t oldpos, newpos; |
|
38 } KeyMapEntry; |
|
39 |
|
40 /* Resource bundle root table */ |
|
41 struct SRBRoot { |
|
42 struct SResource *fRoot; |
|
43 char *fLocale; |
|
44 int32_t fIndexLength; |
|
45 int32_t fMaxTableLength; |
|
46 UBool noFallback; /* see URES_ATT_NO_FALLBACK */ |
|
47 int8_t fStringsForm; /* default STRINGS_UTF16_V1 */ |
|
48 UBool fIsPoolBundle; |
|
49 |
|
50 char *fKeys; |
|
51 KeyMapEntry *fKeyMap; |
|
52 int32_t fKeysBottom, fKeysTop; |
|
53 int32_t fKeysCapacity; |
|
54 int32_t fKeysCount; |
|
55 int32_t fLocalKeyLimit; /* key offset < limit fits into URES_TABLE */ |
|
56 |
|
57 UHashtable *fStringSet; |
|
58 uint16_t *f16BitUnits; |
|
59 int32_t f16BitUnitsCapacity; |
|
60 int32_t f16BitUnitsLength; |
|
61 |
|
62 const char *fPoolBundleKeys; |
|
63 int32_t fPoolBundleKeysLength; |
|
64 int32_t fPoolBundleKeysCount; |
|
65 int32_t fPoolChecksum; |
|
66 }; |
|
67 |
|
68 struct SRBRoot *bundle_open(const struct UString* comment, UBool isPoolBundle, UErrorCode *status); |
|
69 void bundle_write(struct SRBRoot *bundle, const char *outputDir, const char *outputPkg, char *writtenFilename, int writtenFilenameLen, UErrorCode *status); |
|
70 |
|
71 /* write a java resource file */ |
|
72 void bundle_write_java(struct SRBRoot *bundle, const char *outputDir, const char* outputEnc, char *writtenFilename, |
|
73 int writtenFilenameLen, const char* packageName, const char* bundleName, UErrorCode *status); |
|
74 |
|
75 /* write a xml resource file */ |
|
76 /* commented by Jing*/ |
|
77 /* void bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, |
|
78 char *writtenFilename, int writtenFilenameLen,UErrorCode *status); */ |
|
79 |
|
80 /* added by Jing*/ |
|
81 void bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, const char* rbname, |
|
82 char *writtenFilename, int writtenFilenameLen, const char* language, const char* package, UErrorCode *status); |
|
83 |
|
84 void bundle_close(struct SRBRoot *bundle, UErrorCode *status); |
|
85 void bundle_setlocale(struct SRBRoot *bundle, UChar *locale, UErrorCode *status); |
|
86 int32_t bundle_addtag(struct SRBRoot *bundle, const char *tag, UErrorCode *status); |
|
87 |
|
88 const char * |
|
89 bundle_getKeyBytes(struct SRBRoot *bundle, int32_t *pLength); |
|
90 |
|
91 int32_t |
|
92 bundle_addKeyBytes(struct SRBRoot *bundle, const char *keyBytes, int32_t length, UErrorCode *status); |
|
93 |
|
94 void |
|
95 bundle_compactKeys(struct SRBRoot *bundle, UErrorCode *status); |
|
96 |
|
97 /* Various resource types */ |
|
98 |
|
99 /* |
|
100 * Return a unique pointer to a dummy object, |
|
101 * for use in non-error cases when no resource is to be added to the bundle. |
|
102 * (NULL is used in error cases.) |
|
103 */ |
|
104 struct SResource* res_none(void); |
|
105 |
|
106 struct SResTable { |
|
107 uint32_t fCount; |
|
108 int8_t fType; /* determined by table_write16() for table_preWrite() & table_write() */ |
|
109 struct SResource *fFirst; |
|
110 struct SRBRoot *fRoot; |
|
111 }; |
|
112 |
|
113 struct SResource* table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); |
|
114 void table_add(struct SResource *table, struct SResource *res, int linenumber, UErrorCode *status); |
|
115 |
|
116 struct SResArray { |
|
117 uint32_t fCount; |
|
118 struct SResource *fFirst; |
|
119 struct SResource *fLast; |
|
120 }; |
|
121 |
|
122 struct SResource* array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); |
|
123 void array_add(struct SResource *array, struct SResource *res, UErrorCode *status); |
|
124 |
|
125 struct SResString { |
|
126 struct SResource *fSame; /* used for duplicates */ |
|
127 UChar *fChars; |
|
128 int32_t fLength; |
|
129 int32_t fSuffixOffset; /* this string is a suffix of fSame at this offset */ |
|
130 int8_t fNumCharsForLength; |
|
131 }; |
|
132 |
|
133 struct SResource *string_open(struct SRBRoot *bundle, const char *tag, const UChar *value, int32_t len, const struct UString* comment, UErrorCode *status); |
|
134 |
|
135 /** |
|
136 * Remove a string from a bundle and close (delete) it. |
|
137 * The string must not have been added to a table or array yet. |
|
138 * This function only undoes what string_open() did. |
|
139 */ |
|
140 void bundle_closeString(struct SRBRoot *bundle, struct SResource *string); |
|
141 |
|
142 struct SResource *alias_open(struct SRBRoot *bundle, const char *tag, UChar *value, int32_t len, const struct UString* comment, UErrorCode *status); |
|
143 |
|
144 struct SResIntVector { |
|
145 uint32_t fCount; |
|
146 uint32_t *fArray; |
|
147 }; |
|
148 |
|
149 struct SResource* intvector_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); |
|
150 void intvector_add(struct SResource *intvector, int32_t value, UErrorCode *status); |
|
151 |
|
152 struct SResInt { |
|
153 uint32_t fValue; |
|
154 }; |
|
155 |
|
156 struct SResource *int_open(struct SRBRoot *bundle, const char *tag, int32_t value, const struct UString* comment, UErrorCode *status); |
|
157 |
|
158 struct SResBinary { |
|
159 uint32_t fLength; |
|
160 uint8_t *fData; |
|
161 char* fFileName; /* file name for binary or import binary tags if any */ |
|
162 }; |
|
163 |
|
164 struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t length, uint8_t *data, const char* fileName, const struct UString* comment, UErrorCode *status); |
|
165 |
|
166 /* Resource place holder */ |
|
167 |
|
168 struct SResource { |
|
169 int8_t fType; /* nominal type: fRes (when != 0xffffffff) may use subtype */ |
|
170 UBool fWritten; /* res_write() can exit early */ |
|
171 uint32_t fRes; /* resource item word; 0xffffffff if not known yet */ |
|
172 int32_t fKey; /* Index into bundle->fKeys; -1 if no key. */ |
|
173 int line; /* used internally to report duplicate keys in tables */ |
|
174 struct SResource *fNext; /*This is for internal chaining while building*/ |
|
175 struct UString fComment; |
|
176 union { |
|
177 struct SResTable fTable; |
|
178 struct SResArray fArray; |
|
179 struct SResString fString; |
|
180 struct SResIntVector fIntVector; |
|
181 struct SResInt fIntValue; |
|
182 struct SResBinary fBinaryValue; |
|
183 } u; |
|
184 }; |
|
185 |
|
186 const char * |
|
187 res_getKeyString(const struct SRBRoot *bundle, const struct SResource *res, char temp[8]); |
|
188 |
|
189 void res_close(struct SResource *res); |
|
190 |
|
191 void setIncludeCopyright(UBool val); |
|
192 UBool getIncludeCopyright(void); |
|
193 |
|
194 void setFormatVersion(int32_t formatVersion); |
|
195 |
|
196 void setUsePoolBundle(UBool use); |
|
197 |
|
198 /* in wrtxml.cpp */ |
|
199 uint32_t computeCRC(char *ptr, uint32_t len, uint32_t lastcrc); |
|
200 |
|
201 U_CDECL_END |
|
202 #endif /* #ifndef RESLIST_H */ |