]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/toolutil/package.h
2 *******************************************************************************
4 * Copyright (C) 2005-2010, 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 32
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 * 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.
59 void readPackage(const char *filename
);
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
67 void writePackage(const char *filename
, char outType
, const char *comment
);
70 * Return the input data type letter (l, b, or e).
74 // find the item in items[], return the non-negative index if found, else the binary-not of the insertion point
75 int32_t findItem(const char *name
, int32_t length
=-1) const;
78 * Set internal state for following calls to findNextItem() which will return
79 * indexes for items whose names match the pattern.
81 void findItems(const char *pattern
);
82 int32_t findNextItem();
84 * Set the match mode for findItems() & findNextItem().
85 * @param mode 0=default
86 * MATCH_NOSLASH * does not match a '/'
88 void setMatchMode(uint32_t mode
);
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
);
99 void removeItem(int32_t itemIndex
);
100 void removeItems(const char *pattern
);
101 void removeItems(const Package
&listPkg
);
103 /* The extractItem() functions accept outputType=0 to mean "don't swap the item". */
104 void extractItem(const char *filesPath
, int32_t itemIndex
, char outType
);
105 void extractItems(const char *filesPath
, const char *pattern
, char outType
);
106 void extractItems(const char *filesPath
, const Package
&listPkg
, char outType
);
108 /* This variant extracts an item to a specific filename. */
109 void extractItem(const char *filesPath
, const char *outName
, int32_t itemIndex
, char outType
);
111 int32_t getItemCount() const;
112 const Item
*getItem(int32_t idx
) const;
115 * Check dependencies and return TRUE if all dependencies are fulfilled.
117 UBool
checkDependencies();
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
124 void enumDependencies(void *context
, CheckDependency check
);
127 void enumDependencies(Item
*pItem
, void *context
, CheckDependency check
);
130 * Default CheckDependency function used by checkDependencies()
132 static void checkDependency(void *context
, const char *itemName
, const char *targetName
);
135 * Allocate a string in inStrings or outStrings.
136 * The length does not include the terminating NUL.
138 char *allocString(UBool in
, int32_t length
);
143 char inPkgName
[MAX_PKG_NAME_LENGTH
];
146 uint8_t header
[1024];
147 int32_t inLength
, headerLength
;
155 int32_t inStringTop
, outStringTop
;
156 char inStrings
[STRING_STORE_SIZE
], outStrings
[STRING_STORE_SIZE
];
158 // match mode for findItems(pattern) and findNextItem()
161 // state for findItems(pattern) and findNextItem()
162 const char *findPrefix
, *findSuffix
;
163 int32_t findPrefixLength
, findSuffixLength
;
164 int32_t findNextIndex
;
166 // state for checkDependencies()
167 UBool isMissingItems
;
170 * Grow itemMax to new value
172 void setItemCapacity(int32_t max
);
175 * Grow itemMax to at least itemCount+1
177 void ensureItemCapacity();