]>
Commit | Line | Data |
---|---|---|
73c04bcf A |
1 | /* |
2 | ******************************************************************************* | |
3 | * | |
729e4ab9 | 4 | * Copyright (C) 2005-2010, International Business Machines |
73c04bcf A |
5 | * Corporation and others. All Rights Reserved. |
6 | * | |
7 | ******************************************************************************* | |
8 | * file name: package.h | |
9 | * encoding: US-ASCII | |
10 | * tab size: 8 (not used) | |
11 | * indentation:4 | |
12 | * | |
13 | * created on: 2005aug25 | |
14 | * created by: Markus W. Scherer | |
15 | * | |
16 | * Read, modify, and write ICU .dat data package files. | |
17 | */ | |
18 | ||
19 | #ifndef __PACKAGE_H__ | |
20 | #define __PACKAGE_H__ | |
21 | ||
22 | #include "unicode/utypes.h" | |
23 | ||
24 | #include <stdio.h> | |
25 | ||
26 | // .dat package file representation ---------------------------------------- *** | |
27 | ||
28 | #define STRING_STORE_SIZE 100000 | |
73c04bcf A |
29 | #define MAX_PKG_NAME_LENGTH 32 |
30 | ||
46f4442e A |
31 | typedef void CheckDependency(void *context, const char *itemName, const char *targetName); |
32 | ||
73c04bcf A |
33 | U_NAMESPACE_BEGIN |
34 | ||
35 | struct Item { | |
36 | char *name; | |
37 | uint8_t *data; | |
38 | int32_t length; | |
39 | UBool isDataOwned; | |
40 | char type; | |
41 | }; | |
42 | ||
43 | class U_TOOLUTIL_API Package { | |
44 | public: | |
45 | /* | |
46 | * Constructor. | |
47 | * Prepare this object for a new, empty package. | |
48 | */ | |
49 | Package(); | |
50 | ||
51 | /* Destructor. */ | |
52 | ~Package(); | |
53 | ||
54 | /* | |
55 | * Read an existing .dat package file. | |
56 | * The header and item name strings are swapped into this object, | |
57 | * but the items are left unswapped. | |
58 | */ | |
59 | void readPackage(const char *filename); | |
60 | /* | |
61 | * Write a .dat package file with the items in this object. | |
62 | * Swap all pieces to the desired output platform properties. | |
63 | * The package becomes unusable: | |
64 | * The item names are swapped and sorted in the outCharset rather than the local one. | |
65 | * Also, the items themselves are swapped in-place | |
66 | */ | |
67 | void writePackage(const char *filename, char outType, const char *comment); | |
68 | ||
69 | /* | |
70 | * Return the input data type letter (l, b, or e). | |
71 | */ | |
72 | char getInType(); | |
73 | ||
74 | // find the item in items[], return the non-negative index if found, else the binary-not of the insertion point | |
46f4442e | 75 | int32_t findItem(const char *name, int32_t length=-1) const; |
73c04bcf A |
76 | |
77 | /* | |
78 | * Set internal state for following calls to findNextItem() which will return | |
79 | * indexes for items whose names match the pattern. | |
80 | */ | |
81 | void findItems(const char *pattern); | |
82 | int32_t findNextItem(); | |
83 | /* | |
84 | * Set the match mode for findItems() & findNextItem(). | |
85 | * @param mode 0=default | |
86 | * MATCH_NOSLASH * does not match a '/' | |
87 | */ | |
88 | void setMatchMode(uint32_t mode); | |
89 | ||
90 | enum { | |
91 | MATCH_NOSLASH=1 | |
92 | }; | |
93 | ||
94 | void addItem(const char *name); | |
95 | void addItem(const char *name, uint8_t *data, int32_t length, UBool isDataOwned, char type); | |
96 | void addFile(const char *filesPath, const char *name); | |
97 | void addItems(const Package &listPkg); | |
98 | ||
729e4ab9 | 99 | void removeItem(int32_t itemIndex); |
73c04bcf A |
100 | void removeItems(const char *pattern); |
101 | void removeItems(const Package &listPkg); | |
102 | ||
103 | /* The extractItem() functions accept outputType=0 to mean "don't swap the item". */ | |
729e4ab9 | 104 | void extractItem(const char *filesPath, int32_t itemIndex, char outType); |
73c04bcf A |
105 | void extractItems(const char *filesPath, const char *pattern, char outType); |
106 | void extractItems(const char *filesPath, const Package &listPkg, char outType); | |
107 | ||
108 | /* This variant extracts an item to a specific filename. */ | |
729e4ab9 | 109 | void extractItem(const char *filesPath, const char *outName, int32_t itemIndex, char outType); |
73c04bcf | 110 | |
46f4442e A |
111 | int32_t getItemCount() const; |
112 | const Item *getItem(int32_t idx) const; | |
73c04bcf A |
113 | |
114 | /* | |
115 | * Check dependencies and return TRUE if all dependencies are fulfilled. | |
116 | */ | |
117 | UBool checkDependencies(); | |
118 | ||
46f4442e | 119 | /* |
729e4ab9 A |
120 | * Enumerate all the dependencies and give the results to context and call CheckDependency callback |
121 | * @param context user context (will be passed to check function) | |
122 | * @param check will be called with context and any missing items | |
46f4442e A |
123 | */ |
124 | void enumDependencies(void *context, CheckDependency check); | |
125 | ||
73c04bcf | 126 | private: |
46f4442e | 127 | void enumDependencies(Item *pItem, void *context, CheckDependency check); |
73c04bcf | 128 | |
729e4ab9 A |
129 | /** |
130 | * Default CheckDependency function used by checkDependencies() | |
131 | */ | |
73c04bcf A |
132 | static void checkDependency(void *context, const char *itemName, const char *targetName); |
133 | ||
134 | /* | |
135 | * Allocate a string in inStrings or outStrings. | |
136 | * The length does not include the terminating NUL. | |
137 | */ | |
138 | char *allocString(UBool in, int32_t length); | |
139 | ||
140 | void sortItems(); | |
141 | ||
142 | // data fields | |
143 | char inPkgName[MAX_PKG_NAME_LENGTH]; | |
144 | ||
145 | uint8_t *inData; | |
146 | uint8_t header[1024]; | |
147 | int32_t inLength, headerLength; | |
148 | uint8_t inCharset; | |
149 | UBool inIsBigEndian; | |
150 | ||
151 | int32_t itemCount; | |
729e4ab9 A |
152 | int32_t itemMax; |
153 | Item *items; | |
73c04bcf A |
154 | |
155 | int32_t inStringTop, outStringTop; | |
156 | char inStrings[STRING_STORE_SIZE], outStrings[STRING_STORE_SIZE]; | |
157 | ||
158 | // match mode for findItems(pattern) and findNextItem() | |
159 | uint32_t matchMode; | |
160 | ||
161 | // state for findItems(pattern) and findNextItem() | |
162 | const char *findPrefix, *findSuffix; | |
163 | int32_t findPrefixLength, findSuffixLength; | |
164 | int32_t findNextIndex; | |
165 | ||
166 | // state for checkDependencies() | |
167 | UBool isMissingItems; | |
729e4ab9 A |
168 | |
169 | /** | |
170 | * Grow itemMax to new value | |
171 | */ | |
172 | void setItemCapacity(int32_t max); | |
173 | ||
174 | /** | |
175 | * Grow itemMax to at least itemCount+1 | |
176 | */ | |
177 | void ensureItemCapacity(); | |
73c04bcf A |
178 | }; |
179 | ||
180 | U_NAMESPACE_END | |
181 | ||
182 | #endif | |
729e4ab9 A |
183 | |
184 |