]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/toolutil/package.h
2 *******************************************************************************
4 * Copyright (C) 2005-2014, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 2005aug25
14 * created by: Markus W. Scherer
16 * Read, modify, and write ICU .dat data package files.
22 #include "unicode/utypes.h"
26 // .dat package file representation ---------------------------------------- ***
28 #define STRING_STORE_SIZE 100000
29 #define MAX_PKG_NAME_LENGTH 64
31 typedef void CheckDependency(void *context
, const char *itemName
, const char *targetName
);
43 class U_TOOLUTIL_API Package
{
47 * Prepare this object for a new, empty package.
55 * Uses the prefix of the first entry of the package in readPackage(),
56 * rather than the package basename.
58 void setAutoPrefix() { doAutoPrefix
=TRUE
; }
60 * Same as setAutoPrefix(), plus the prefix must end with the platform type letter.
62 void setAutoPrefixWithType() {
64 prefixEndsWithType
=TRUE
;
66 void setPrefix(const char *p
);
69 * Read an existing .dat package file.
70 * The header and item name strings are swapped into this object,
71 * but the items are left unswapped.
73 void readPackage(const char *filename
);
75 * Write a .dat package file with the items in this object.
76 * Swap all pieces to the desired output platform properties.
77 * The package becomes unusable:
78 * The item names are swapped and sorted in the outCharset rather than the local one.
79 * Also, the items themselves are swapped in-place
81 void writePackage(const char *filename
, char outType
, const char *comment
);
84 * Return the input data type letter (l, b, or e).
88 // find the item in items[], return the non-negative index if found, else the binary-not of the insertion point
89 int32_t findItem(const char *name
, int32_t length
=-1) const;
92 * Set internal state for following calls to findNextItem() which will return
93 * indexes for items whose names match the pattern.
95 void findItems(const char *pattern
);
96 int32_t findNextItem();
98 * Set the match mode for findItems() & findNextItem().
99 * @param mode 0=default
100 * MATCH_NOSLASH * does not match a '/'
102 void setMatchMode(uint32_t mode
);
108 void addItem(const char *name
);
109 void addItem(const char *name
, uint8_t *data
, int32_t length
, UBool isDataOwned
, char type
);
110 void addFile(const char *filesPath
, const char *name
);
111 void addItems(const Package
&listPkg
);
113 void removeItem(int32_t itemIndex
);
114 void removeItems(const char *pattern
);
115 void removeItems(const Package
&listPkg
);
117 /* The extractItem() functions accept outputType=0 to mean "don't swap the item". */
118 void extractItem(const char *filesPath
, int32_t itemIndex
, char outType
);
119 void extractItems(const char *filesPath
, const char *pattern
, char outType
);
120 void extractItems(const char *filesPath
, const Package
&listPkg
, char outType
);
122 /* This variant extracts an item to a specific filename. */
123 void extractItem(const char *filesPath
, const char *outName
, int32_t itemIndex
, char outType
);
125 int32_t getItemCount() const;
126 const Item
*getItem(int32_t idx
) const;
129 * Check dependencies and return TRUE if all dependencies are fulfilled.
131 UBool
checkDependencies();
134 * Enumerate all the dependencies and give the results to context and call CheckDependency callback
135 * @param context user context (will be passed to check function)
136 * @param check will be called with context and any missing items
138 void enumDependencies(void *context
, CheckDependency check
);
141 void enumDependencies(Item
*pItem
, void *context
, CheckDependency check
);
144 * Default CheckDependency function used by checkDependencies()
146 static void checkDependency(void *context
, const char *itemName
, const char *targetName
);
149 * Allocate a string in inStrings or outStrings.
150 * The length does not include the terminating NUL.
152 char *allocString(UBool in
, int32_t length
);
157 char inPkgName
[MAX_PKG_NAME_LENGTH
];
158 char pkgPrefix
[MAX_PKG_NAME_LENGTH
];
161 uint8_t header
[1024];
162 int32_t inLength
, headerLength
;
166 UBool prefixEndsWithType
;
172 int32_t inStringTop
, outStringTop
;
173 char inStrings
[STRING_STORE_SIZE
], outStrings
[STRING_STORE_SIZE
];
175 // match mode for findItems(pattern) and findNextItem()
178 // state for findItems(pattern) and findNextItem()
179 const char *findPrefix
, *findSuffix
;
180 int32_t findPrefixLength
, findSuffixLength
;
181 int32_t findNextIndex
;
183 // state for checkDependencies()
184 UBool isMissingItems
;
187 * Grow itemMax to new value
189 void setItemCapacity(int32_t max
);
192 * Grow itemMax to at least itemCount+1
194 void ensureItemCapacity();