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