]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ******************************************************************************* | |
3 | * | |
4388f060 | 4 | * Copyright (C) 2000-2011, International Business Machines |
b75a7d8f A |
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 | ||
374ca955 | 21 | #define KEY_SPACE_SIZE 65536 |
b75a7d8f A |
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" | |
374ca955 | 31 | #include "ustr.h" |
729e4ab9 | 32 | #include "uhash.h" |
b75a7d8f A |
33 | |
34 | U_CDECL_BEGIN | |
35 | ||
729e4ab9 A |
36 | typedef struct KeyMapEntry { |
37 | int32_t oldpos, newpos; | |
38 | } KeyMapEntry; | |
39 | ||
b75a7d8f A |
40 | /* Resource bundle root table */ |
41 | struct SRBRoot { | |
374ca955 | 42 | struct SResource *fRoot; |
729e4ab9 A |
43 | char *fLocale; |
44 | int32_t fIndexLength; | |
374ca955 | 45 | int32_t fMaxTableLength; |
73c04bcf | 46 | UBool noFallback; /* see URES_ATT_NO_FALLBACK */ |
729e4ab9 A |
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; | |
b75a7d8f A |
66 | }; |
67 | ||
729e4ab9 | 68 | struct SRBRoot *bundle_open(const struct UString* comment, UBool isPoolBundle, UErrorCode *status); |
b75a7d8f A |
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); | |
374ca955 | 86 | int32_t bundle_addtag(struct SRBRoot *bundle, const char *tag, UErrorCode *status); |
b75a7d8f | 87 | |
729e4ab9 A |
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 | ||
b75a7d8f A |
97 | /* Various resource types */ |
98 | ||
46f4442e A |
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 | ||
b75a7d8f | 106 | struct SResTable { |
374ca955 | 107 | uint32_t fCount; |
729e4ab9 | 108 | int8_t fType; /* determined by table_write16() for table_preWrite() & table_write() */ |
b75a7d8f A |
109 | struct SResource *fFirst; |
110 | struct SRBRoot *fRoot; | |
111 | }; | |
112 | ||
729e4ab9 | 113 | struct SResource* table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); |
b75a7d8f A |
114 | void table_add(struct SResource *table, struct SResource *res, int linenumber, UErrorCode *status); |
115 | ||
116 | struct SResArray { | |
117 | uint32_t fCount; | |
b75a7d8f A |
118 | struct SResource *fFirst; |
119 | struct SResource *fLast; | |
120 | }; | |
121 | ||
73c04bcf | 122 | struct SResource* array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); |
b75a7d8f A |
123 | void array_add(struct SResource *array, struct SResource *res, UErrorCode *status); |
124 | ||
125 | struct SResString { | |
729e4ab9 | 126 | struct SResource *fSame; /* used for duplicates */ |
b75a7d8f | 127 | UChar *fChars; |
729e4ab9 A |
128 | int32_t fLength; |
129 | int32_t fSuffixOffset; /* this string is a suffix of fSame at this offset */ | |
130 | int8_t fNumCharsForLength; | |
b75a7d8f A |
131 | }; |
132 | ||
4388f060 | 133 | struct SResource *string_open(struct SRBRoot *bundle, const char *tag, const UChar *value, int32_t len, const struct UString* comment, UErrorCode *status); |
b75a7d8f | 134 | |
729e4ab9 A |
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 | ||
4388f060 | 142 | struct SResource *alias_open(struct SRBRoot *bundle, const char *tag, UChar *value, int32_t len, const struct UString* comment, UErrorCode *status); |
b75a7d8f A |
143 | |
144 | struct SResIntVector { | |
145 | uint32_t fCount; | |
146 | uint32_t *fArray; | |
147 | }; | |
148 | ||
4388f060 | 149 | struct SResource* intvector_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); |
b75a7d8f A |
150 | void intvector_add(struct SResource *intvector, int32_t value, UErrorCode *status); |
151 | ||
152 | struct SResInt { | |
153 | uint32_t fValue; | |
154 | }; | |
155 | ||
4388f060 | 156 | struct SResource *int_open(struct SRBRoot *bundle, const char *tag, int32_t value, const struct UString* comment, UErrorCode *status); |
b75a7d8f A |
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 | ||
374ca955 | 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); |
b75a7d8f A |
165 | |
166 | /* Resource place holder */ | |
167 | ||
168 | struct SResource { | |
729e4ab9 A |
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 */ | |
b75a7d8f | 174 | struct SResource *fNext; /*This is for internal chaining while building*/ |
46f4442e | 175 | struct UString fComment; |
b75a7d8f A |
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 | ||
729e4ab9 A |
186 | const char * |
187 | res_getKeyString(const struct SRBRoot *bundle, const struct SResource *res, char temp[8]); | |
188 | ||
46f4442e | 189 | void res_close(struct SResource *res); |
729e4ab9 | 190 | |
b75a7d8f A |
191 | void setIncludeCopyright(UBool val); |
192 | UBool getIncludeCopyright(void); | |
193 | ||
729e4ab9 A |
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 | ||
b75a7d8f A |
201 | U_CDECL_END |
202 | #endif /* #ifndef RESLIST_H */ |